After the following example is executed successfully, the table in mongodb is tests, and a character "s" is automatically added. This is a pit! ! !
var mongoose = require("mongoose");
mongoose.connect("mongodb://192.168.1.17:27017/test",function(e){if(e)
console.log(e.message);
console.log("connect ok!");
});
var Schema = mongoose.Schema; // Create a model
var userScheMa = new Schema({
carrier: String,
lang: String,
impCount: Number,
clickCount: Number,
}); // A new model is defined, but this model also Not associated with the test_table collection
var data = mongoose.model('test_table', userScheMa); // Associated with the test_table collection
exports.query = function(req, res){
var key1 = {carrier: "$carrier", lang: "$lang"}
var query1 = {'$or': [{'impCount': {'$gt': 3}}, {'impCount': {'$lt' : 16}}] }
var sort1 = { os: -1 }
var limit1 = 3
var skip1 = 0
data.aggregate(
[
{ $match: query1},
{ $group: { _id: key1 , ImpCount: { $sum: "$impCount" }, ClickCount:{$sum: "$clickCount" }}},
{ $sort: sort1},
{ $limit: limit1 },
{ $skip : skip1}
],function(e,docs)
{
if(e)
console.log(e.message);
res.send(JSON.stringify(docs));
}
);
};