Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のようなコレクションがあります。
{ 'datetime': some-date, 'lat': '32.00', 'lon': '74.00' }, { 'datetime': some-date, 'lat': '32.00', 'lon': '74.00' }
datetime が最新の MongoDB から最新のレコードを取得するにはどうすればよいですか? 私は単一のレコードだけが欲しいです。
とを使用sortしlimitます。
sort
limit
db.col.find().sort({"datetime": -1}).limit(1)
次の関数node.jsを使用できます。findOne()
node.js
findOne()
db.collection('yourCollectionName').findOne( {}, { sort: { datetime: -1 } }, (err, data) => { console.log(data); }, );