[英]Model.find() is not a function
我試圖通過查找模型的postalValue進行查詢,但出現的錯誤是說沒有方法find() 。
下面是從數據庫查詢時遇到的錯誤。
modelInstance.find({postalValue:123344})。then(model => ^ TypeError:modelInstance.find不是Object的函數。(/Users/biswajeet/Documents/webdriverio-test-framework/src/vendor/dataTest.js :44:15)在Module._compile(內部/模塊/cjs/loader.js:701:30)在Object.Module._extensions..js(內部/模塊/cjs/loader.js:712:10)在Function.Module._load(internal / modules / cjs / loader.js)的tryModuleLoad(internal / modules / cjs / loader.js:539:12)的.load(internal / modules / cjs / loader.js:600:32) :531:3)在啟動時(Function / Module.runMain(internal / modules / cjs / loader.js:754:12)(internal / bootstrap / node.js:283:19)在bootstrapNodeJSCore(internal / bootstrap / node。 js:622:3)
const modelInstance = new RegisterModel({
cred: {
nameValue: 'Sample',
emailValue: 'sample@gmail.com',
passwordValue: 'sample122',
},
location: {
addressValue: 'sample address',
cityValue: 'sample',
stateValue: 'sample',
postalValue: 123344,
},
card: {
cardName: 'Sample',
cardNumber: 231232143,
securityCode: 131,
expirationMonth: 1,
expirationYear: 2022,
},
})
modelInstance.save(function (err) {
console.log('@@@@@ Inside the callback ', err);
if (err) {
console.log('the error is ', err);
}
console.log('saved the model instance @@@@@@');
console.log(modelInstance, '@@@@@Helllo@@@@@');
});
modelInstance.find({postalValue: 123344 }).then(model=>
console.log('model@@@',model)
)
在貓鼬中,您必須執行RegisterModel.find()
因為modelInstance
是RegisterModel
的實例,並且find()
查詢在模型上而不是模型實例上運行。 同樣的事情適用於findOne
和findById
。
但是為了save
請使用modelInstance.save
因為您實際上是在保存更新的數據。 因此,如果該文檔的至少一個屬性被修改,這也將迫使mongodb更新記錄的版本值,即__v
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.