Promise findOneAsync variable = {"isFulfilled":false,"isRejected":false}? Promise findOneAsync variable = {"isFulfilled":false,"isRejected":false}? mongoose mongoose

Promise findOneAsync variable = {"isFulfilled":false,"isRejected":false}?


Your question is not really clear, but my question to you would be: why would existingItem not be pending right after you retrieved it?

Do you understand how to use promises? Most of the time you need to get at their resolved values using .then() or other promise manipulation functions:

var existingItem = Models.Items.findOneAsync({ item: items[i] });existingItem.then(function (value) {    console.log( "existingItem : ");    console.log( JSON.stringify(existingItem) );    console.log( JSON.stringify(value); );    console.log( "existingItem._id : " + existingItem._id );});


You need to wait until the promise gets resolved (or rejected).You can use any one of the following two ways:

1. By 'awaiting' to get the final state of the promise as follows:

var existingItem = await Models.Items.findOneAsync({ item: items[i] });

2. By handling the promise using '.then' handler as follows:

return Models.Items.findOneAsync({ item: items[i] })    .then(function(existingItem) {        console.log("existingItem", existingItem);


I think you want:

return Promise.each(items, function(item) {  return Models.Items.findOneAsync({item: item}).then(function(existingItem) {    console.log("existingItem", existingItem);  });});