How to run SlaveOk in Mongoose?

前提是你 提交于 2019-12-04 22:12:56

Here's the official example from the Mongoose.js website:

Model
.where('age').gte(25)
.where('tags').in(['movie', 'music', 'art'])
.select('name', 'age', 'tags')
.skip(20)
.limit(10)
.asc('age')
.slaveOk()
.hint({ age: 1, name: 1 })
.run(callback);

So I guess your example above would probably work, but do it like so:

Model.find(conditions).slaveOk().run(callback);

mongoose.Query.slaveOk has been deprecated in favour of mongoose.Query.read(readPreference). docs

So, to iterate on the example above:

Model
.where('age').gte(25)
.where('tags').in(['movie', 'music', 'art'])
.select('name', 'age', 'tags')
.skip(20)
.limit(10)
.asc('age')
.read('secondaryPreferred')
.hint({ age: 1, name: 1 })
.run(callback);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!