Reputation: 5539
Json Structure:
{"address": {"building": "1007", "coord": [-73.856077, 40.848447], "street": "Morris Park Ave", "zipcode": "10462"}, "borough": "Bronx", "cuisine": "Bakery", "grades": [{"date": {"$date": 1393804800000}, "grade": "A", "score": 2}, {"date": {"$date": 1378857600000}, "grade": "A", "score": 6}, {"date": {"$date": 1358985600000}, "grade": "A", "score": 10}, {"date": {"$date": 1322006400000}, "grade": "A", "score": 9}, {"date": {"$date": 1299715200000}, "grade": "B", "score": 14}], "name": "Morris Park Bake Shop", "restaurant_id": "30075445"},...
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
// Connection URL
const url = 'mongodb://localhost:27017';
// Database Name
const dbName = 'restaurant';
MongoClient.connect(url, function(err, client) {
const db = client.db(dbName);
const collection = db.collection('restaurants');
collection.find({}, {"restaurant_id": "40386837"}).toArray(function(err,docs){
console.log(docs)
});
});
Output:
There is only one record that matches the criteria "restaurant_id": "40386837" but I am getting all of it.
Upvotes: 0
Views: 47
Reputation: 184
I think your query should be the first thing you pass, not the second:
find(query, projection)
so:
collection.find({"restaurant_id": "40386837"})
see docs: https://docs.mongodb.com/realm/mongodb/actions/collection.find/
Upvotes: 2