【问题标题】:Ignore Mongoose schema on read only在只读模式下忽略 Mongoose 架构
【发布时间】:2018-12-01 16:14:20
【问题描述】:

我有一个数据符合几种不同模式之一的集合。这些都在一个集合中的原因是我需要能够一起查询它们,利用 MongoDB 的无模式特性。

有没有办法在忽略模式的情况下使用 mongoose 查询集合?举个例子:

var adam = new ContractCustomer({
  // Contract customer data saved to customers collection
})

var betty = new PaygCustomer({
  // PAYG customer data saved to customers collection
})

adam.save()
betty.save()

Customers.find({}).exec().then() // Query all the customers regardless of which schema they belong to.

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    我建议使用mongodb-driver 连接到数据库,并从那里创建一个find。据我所知,没有办法使用 mongoose 执行无模式查询。

    猫鼬的全部意义在于使用模式。

    (保持与猫鼬的连接,只需打开一个并行连接)

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 1970-01-01
      • 2021-10-15
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多