如何$in在mongoDB中与聚合一起编写查询?我想为下面的SQL写一个等效的mongoDB查询
SELECT name,count(something) from collection1
where name in (<<list of Array>>) and cond1 = 'false'
group by name
Run Code Online (Sandbox Code Playgroud) 这是我的数据:
[
{
id: 1,
starttime: ISODate("2015-08-24T00:00:00.000Z"),
endtime: ISODate("2015-08-24T07:00:00.000Z")
},
{
id: 2,
starttime: ISODate("2015-08-24T20:00:00.000Z"),
endtime: ISODate("2015-08-25T01:00:00.000Z")
}
]
Run Code Online (Sandbox Code Playgroud)
我可以创建一个mongodb查询来显示starttime和endtime的持续时间(或者在这种情况下是差异操作),结果如下:
[ {id:1, duration: 7}, {id: 2, duration: 5}]
Run Code Online (Sandbox Code Playgroud)
请注意,时间戳可以具有不同的日期,因此$hour(聚合管道)可能不起作用.有人可以帮忙吗?谢谢
我使用 mongoTemplate 查询我的 mongodb 数据库,并且我想在我的集合中进行一些计数。我想按 id 分组并包括条件计数。我在 mongoshell 中使用了这个查询
db.scenarios.aggregate([
{ $match: { bid: "build_1481711758" } },
{
$group: {
_id: "$bid",
nb: { $sum: 1 },
nbS: {
"$sum": {
"$cond": [
{ "$eq": ["$scst", true ] },
1, 0
]
}
},
nbE: {
"$sum": {
"$cond": [
{ "$eq": ["$scst", false ] },
1, 0
]
}
}
}
}
])
Run Code Online (Sandbox Code Playgroud)
它返回我想要的,但我不知道如何将其转换为 java mongotemplate。
请帮忙 :)
java mongodb mongodb-query aggregation-framework mongotemplate
System.String在ILSpyI中观察类找到了以下索引器:
public extern char this[int index]
{
[__DynamicallyInvokable, SecuritySafeCritical]
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
Run Code Online (Sandbox Code Playgroud)
这个索引器通过索引从字符串中取出char并限制它的setter(我认为它是不可变的).但这个吸气剂是如何起作用的?它从哪里取出炭?调试器如何自动实现这个索引器getter?
我在ext js中有以下代码
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', action.result.message);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response');
}
Run Code Online (Sandbox Code Playgroud)
提交就像一个以两个参数为参数的函数或者我对它的理解是不正确的?
我正在尝试修改多个文档findAndModify,然后返回修改的新文档.我的查询是:
db.users.findAndModify({
query: {
_id: {
$in: [
ObjectId("54061f3c27afac4b44688c1d"),
ObjectId("54061f3c27afac4b44688c1e")
]
}
},
update: {
$inc: {
i: 1
}
},
new: true
});
Run Code Online (Sandbox Code Playgroud)
但只能检索一个文档.我的目标是修改多个文档,并返回所有文档.是否可以检索文档数组?
我用谷歌搜索了一整天,但没有找到任何解决方案来改变窗口系统的meteor中的默认数据库.所有发现如下
MONGO_URL=mongodb://127.0.0.1:27018/meteor meteor
Run Code Online (Sandbox Code Playgroud)
在窗口系统上给出错误 -
"MONGO_URL"未被识别为内部或外部命令,
使用了settings.json作为
{
"MONGO_URL":"mongodb://127.0.0.1:27018/meteor"
}
Run Code Online (Sandbox Code Playgroud)
然后是流星 --settings ./settings.json
但它仍然没有选择这个mongo设置.最后在我的js文件中
if (Meteor.isServer){
process.env.MONGO_URL="mongodb://127.0.0.1:27018/meteor"
}
Run Code Online (Sandbox Code Playgroud)
这也行不通.任何有关这方面的建议都将受到高度赞赏.
我有2个收藏:
每天一次,我想计算过去一年,过去一个月和过去一周的订单数量等等.
我试过这个:
db.orders.aggregate(
{$match:
{ date_order: { $gt: v_date1year } }
},
{$group : {
_id : "$id_client",
count : {$sum : 1}
}} ,
{
"$out": "tmp_indicators"
}
)
db.tmp_indicators.find({}).forEach(function (my_client) {
db.clients.update (
{"id_client": my_client._id},
{"$set":
{ "nb_orders_1year" : my_client.count }
}
)
})
Run Code Online (Sandbox Code Playgroud)
我必须这样做3次,过去一年聚合1次,过去一个月1次,过去一周1次.治疗非常缓慢,您是否知道如何以更好的方式执行它?
我的收藏包含以下文件。我想使用聚合来计算内部有多少客户,但我遇到了一些问题。我可以得到总行,但不能得到总(唯一)客户。
[{
_id: "n001",
channel: "Kalipare",
trans: {
_id: "trans001",
customerID: "customerCXLA93",
customerName: "Kalipare Fried Chicked"
}
}, {
_id: "n002",
channel: "Kalipare",
trans: {
_id: "trans002",
customerID: "customerCXLA93",
customerName: "Kalipare Fried Chicked"
}
}, {
_id: "n003",
channel: "Kalipare",
trans: {
_id: "trans003",
customerID: "customerPWR293",
customerName: "Kalipare Papabun"
}
}, {
_id: "n004",
channel: "Kalipare",
trans: {
_id: "trans004",
customerID: "customerPWR293",
customerName: "Kalipare Papabun"
}
}, {
_id: "n005",
channel: "Tumpakrejo",
trans: {
_id: "trans005",
customerID: "customerPWR293",
customerName: "Tumpakrejo …Run Code Online (Sandbox Code Playgroud) 我希望在SQL中使用mongo db中的查询:
Select * from Users
where familyId =@X and (isDeleted =false or isDeleted is null)
Run Code Online (Sandbox Code Playgroud)
已经我有第一个条件,我不知道如何将它与And-Or混合
var myMembers = Meteor.users.find({ "profile.family_id": Meteor.user().profile.family_id });
Run Code Online (Sandbox Code Playgroud)
应该怎么可能?