只读时忽略猫鼬模式

时间:2018-06-22 08:17:18

标签: node.js mongodb mongoose

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

有没有一种方法可以在忽略模式的情况下用猫鼬查询集合?例如:

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.

1 个答案:

答案 0 :(得分:0)

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

猫鼬的全部重点是使用模式。

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