'I want to find the last object which i'm posting in my database without any condition but i can't find any method for that

Data.findOne({}).then((respp)=>console.log(respp, "find one"))

Like I have this method this is returning First object and if I apply a condition then i can get only matched element but i want every-time when data is submitted the last submitted object I need and then I can use that for my further process

I want to call a specifc function and want to pass the latest object which i need to get from mongodb to that function like that Data.findOne({ want to get last submitted dobject here }).then((respp)=> addRow(respp))



Solution 1:[1]

sort data on _id. this provides the latest document in the collection

Data.findOne({}).sort({_id:-1}).then((respp)=>console.log(respp, "find one"))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jitendra chauhan