Mongodb 如何使用特定用户id和子文档字段数组不等于null来框显mongo db查询
考虑下面的例子。由此,我想在mongo db中构建一个查询,该查询的UserId:“test”和“Orders.PaidDateTime”不等于null 我应该得到以下结果 例如:Mongodb 如何使用特定用户id和子文档字段数组不等于null来框显mongo db查询,mongodb,mongodb-query,database,Mongodb,Mongodb Query,Database,考虑下面的例子。由此,我想在mongo db中构建一个查询,该查询的UserId:“test”和“Orders.PaidDateTime”不等于null 我应该得到以下结果 例如: { "_id" : ObjectId("5953b6873a45f70afc6ce3a2"), "CreatedDateTime" : ISODate("2017-06-28T14:00:39.192Z"), "UserId" : "test", "Orders" : [
{
"_id" : ObjectId("5953b6873a45f70afc6ce3a2"),
"CreatedDateTime" : ISODate("2017-06-28T14:00:39.192Z"),
"UserId" : "test",
"Orders" : [
{
"_id" : ObjectId("59560f2b844faa0ff4933aa6"),
"CreatedDateTime" : ISODate("2017-06-30T08:43:23.666Z"),
"PaidDateTime" : null
},
{
"_id" : ObjectId("59564ba3a046041364c24de4"),
"CreatedDateTime" : ISODate("2017-06-30T13:01:23.290Z"),
"PaidDateTime" : null
},
{
"_id" : ObjectId("59564f168be0720e1c346857"),
"CreatedDateTime" : ISODate("2017-06-30T13:16:06.072Z"),
"PaidDateTime" : ISODate("2017-06-30T13:16:29.000Z")
}
]
},
{
"_id" : ObjectId("5953b6873a45f70afc6ce3a2"),
"CreatedDateTime" : ISODate("2017-06-28T14:00:39.192Z"),
"UserId" : "test",
"Orders" : [
{
"_id" : ObjectId("59560f2b844faa0ff4933aa6"),
"CreatedDateTime" : ISODate("2017-06-30T08:43:23.666Z"),
"PaidDateTime" : null
}
]
}
结果:
{
"_id" : ObjectId("5953b6873a45f70afc6ce3a2"),
"CreatedDateTime" : ISODate("2017-06-28T14:00:39.192Z"),
"UserId" : "test",
"Orders" : [
{
"_id" : ObjectId("59564f168be0720e1c346857"),
"CreatedDateTime" : ISODate("2017-06-30T13:16:06.072Z"),
"PaidDateTime" : ISODate("2017-06-30T13:16:29.000Z")
}
]
}
使用$ne opertaor
db.inventory.find({UserId:“test”,“Orders.PaidDateTime:{$ne:null}})使用$ne operator
db.inventory.find({UserId:“test”,“Orders.PaidDateTime:{$ne:null}}})它没有返回任何记录。我尝试了以下方法,即使这是返回零记录db.getCollection('User')。find({“UserId:”test“,”Orders.PaidDateTime:{$exists:true,$ne:null})请告诉我是否有其他解决方案。。。ThanksIt没有返回任何记录。我尝试了以下操作,即使这是返回零记录db.getCollection('User')。查找({“UserId”:“test”,“Orders.PaidDateTime”:{$exists:true,$ne:null})请告诉我是否有其他解决方案。。。谢谢有人在这个问题上提供帮助吗?有人能在这个问题上提供帮助吗?