这些模块是必需的
const crypto = require('crypto');
const bcrypt = require('bcrypt');
Run Code Online (Sandbox Code Playgroud)
他们之间我很困惑.我想知道它们之间的区别以及它何时应该被使用.
我已经使用了聚合函数。
db.checkins.aggregate([
{$match: {checkinType: "Beacon",
"associationIds.organizationId":"af39bc69-1938-4149",
"checkinData.time": {"$gte": new Date("2018-01-18T18:30:00.000Z"),
"$lt": new Date("2018-01-19T18:30:00.000Z")}
}
},
{"$sort":{"checkinData.time":-1}},
{$group: {"_id":
{"orgId":"$asst.organizationId", "userId":"$asst.userId"},
"lastSeen":{"$first":"$checkinData.time"},
"firstSeen":{"$last":"$checkinData.time"},
}
},
{"$project":{"_id":1,"lastSeen":1, "firstSeen":1,
totalHourSpent:{$subtract: ["$lastSeen","$firstSeen"]}}},
])
Run Code Online (Sandbox Code Playgroud)
当我执行此查询mongo时,以毫秒为单位返回totalHourSpent,如下所示。
{
"_id" : {
"orgId" : "af39bc69-1938-4149-b9f7-f101fd9baf73",
"userId" : "34adb4a0-0012-11e7-bf32-cf79d6b423e9"
},
"lastSeen" : ISODate("2018-01-19T18:49:52.242+05:30"),
"firstSeen" : ISODate("2018-01-19T10:08:21.026+05:30"),
"totalHourSpent" : NumberLong("31291216")
},
{
"_id" : {
"orgId" : "af39bc69-1938-4149-b9f7-f101fd9baf73",
"userId" : "679416b0-3f88-11e7-8d27-77235eb1ba9b"
},
"lastSeen" : ISODate("2018-01-19T20:51:30.946+05:30"),
"firstSeen" : ISODate("2018-01-19T11:07:44.256+05:30"),
"totalHourSpent" : NumberLong("35026690")
},
Run Code Online (Sandbox Code Playgroud)
如何以小时为单位计算totalHourSpent。提前致谢。
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'ABC',
log: 'trace',
apiVersion: '7.1'
});
client.delete({
index: 'allevents',
type: '_doc',
id:"2"
}).then(function(resp) {
console.log("Successful query!");
console.log(JSON.stringify(resp, null, 4));
}, function(err) {
console.trace(err.message);
});
Run Code Online (Sandbox Code Playgroud)
当我通过传递单个 id 值删除单个文档时,它工作正常。
但我想在单个查询中删除多个文档。我们会怎么做?
我试过
client.delete({
index: 'allevents',
type: '_doc',
id: ["2","3"]
})
Run Code Online (Sandbox Code Playgroud)
该函数返回错误。
汇总查询返回错误。
'猫鼬5.x不允许将大量操作员传递给Model.aggregate()。代替Model.aggregate({ $match }, { $skip }),做Model.aggregate([{ $match }, { $skip }]),
我正在使用mongoose和MongoDb版本
“ mongoose”:“ ^ 5.5.4”,mongod版本:3.6.12
请建议我,我将非常感谢您。
node.js ×3
javascript ×2
mongodb ×2
aggregate ×1
bcrypt ×1
cryptography ×1
mlab ×1
mongoose ×1