猫鼬在子图案属性上查找查询

发布于 2025-02-09 09:52:10 字数 458 浏览 1 评论 0原文

我需要使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文