猫鼬在子图案属性上查找查询
我需要使用Mongoose在MongoDB数据库上执行查询,以根据子记录中包含的属性值选择文档。 这些是我的模式:
type Map{
id: ID
date: String!
parcels: [Parcel!]!
}
type Parcel {
id: Int
name: String!
x: Int!
y: Int!
}
我想在给定日期通过坐标找到一个包裹,所以我尝试了这些查询,但我总是毫无疑问:
Map.find({date: "2022-06-15", parcels:{x: 10, y:20}})
Map.find({date: "2022-06-15", "parcels.x": 10, "parcels.y":20})
有什么方法可以避免检索所有包裹,然后选择我正在寻找的一个?
I need to perform a query on a MongoDB database using mongoose to select documents based on the value of properties contained in subdocuments.
These are my schemas:
type Map{
id: ID
date: String!
parcels: [Parcel!]!
}
type Parcel {
id: Int
name: String!
x: Int!
y: Int!
}
I'd like to find a parcel by coordinates at a given date, so I tried these queries but I always get null:
Map.find({date: "2022-06-15", parcels:{x: 10, y:20}})
Map.find({date: "2022-06-15", "parcels.x": 10, "parcels.y":20})
Is there any way to avoid retrieving all parcels and then selecting the one I'm looking for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论