0

我们最近从托管的 mongodb 迁移到 azure cosmos db 4.0 版本。我们发现以下 db 查询存在问题,该查询在托管的 mongodb 中有效,但 cosmos db 产生了不同的结果。

db.getCollection('customers').aggregate([{ "$match" : {}}, { "$project" : { "status" : "EXPIRED", "expiryDate" : 1, "customerName" : 1, " customerIdentificationNumber”:1,“qty”:1,“custNo”:1,“createdOn”:1,“startDate”:1,“userId”:1,“_id”:1}},{“$match”:{ }},{“$sort”:{“customerIdentificationNumber”:-1,“customerName”:1}},{“$group”:{“_id”:null,“totalCount”:{“$sum”:1} ,“联系人”:{“$push”:“$$ROOT”}}},{“$project”:{“totalCount”:1,“contactList”:{“$slice”:[“$contacts”,0 , 10]}}}])

在 cosmosdb 中,我们只能看到排序中包含的那些字段。输出中看不到其他字段。

cosmosDB 中查询的输出

{“_id”:null,“totalCount”:2.0,“contactList”:[{“customerName”:“TATA”,“customerIdentificationNumber”:“56189212”,“status”:“EXPIRED”},{“customerName”:“ TATA”,“customerIdentificationNumber”:“210021”,“状态”:“过期”}]}

mongodb中查询的输出

{“_id”:空,“totalCount”:2.0,“contactList”:[{“_id”:ObjectId(“5fe443d63d3a8b16ff66aaaa”),“customerName”:“TATA”,“customerIdentificationNumber”:“UH13”,“qty”: 100.0,“custNo”:“CUST12”,“createdOn”:ISODate(“2020-12-24T07:31:34.007Z”),“startDate”:ISODate(“2020-07-10T00:00:00.000Z”), “expiryDate”:ISODate(“2021-01-28T00:00:00.000Z”),“userId”:“cust1@gmail.com”,“status”:“EXPIRED”},{“_id”:ObjectId(“5fe45f913d3a8b16ff66hac8 "), "customerName" : "TATA", "customerIdentificationNumber" : "NN66", "qty" : 100.0, "custNo" : "CUST77", "createdOn" : ISODate("2020-12-24T09:29:53.280Z"), "startDate" : ISODate("2020-07-10T00:00:00.000Z"), "expiryDate" : ISODate(" 2021-01-28T00:00:00.000Z"), "userId" : "cust2@gmail.com", "status" : "EXPIRED" } ] }

谁能建议我们如何使这个查询在 cosmos db 中像在 mongodb 中一样工作?任何帮助将不胜感激

4

0 回答 0