Reputation: 119
I have to connect to a mongo database with mongoose to preform a query. I have done similar before but in that case I defined the schema and the model so I made operations with the exported then required model in the application.
For this task I was provided with the mongoose connection's uri and the collections's name only and I have to make a node app and query the collection.
What is the way to query the collection with mongoose in this case?
Thanks for your help in advance.
Upvotes: 1
Views: 119
Reputation: 1341
You must be good to go with below code.
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
mongoose.connect("uri");
var abcSchema = new Schema({
strict: false
}, {
collection: 'collectionName'
});
var abc = mongoose.model('collectionName', abcSchema);
abc.operations...
Upvotes: 1