sandeep
sandeep

Reputation: 175

Mongoose find data from dynamic Collection

I am new to MongoDB & working on a MEAN application. In the mongo database(I am using mongoose), the collections are adding dynamically from third party API like schoolList1,schoolList2,schoolList3,schoolList4,....

I am facing problem to find a solution to get data from collections, Like If a user sends the argument from FrontEnd to find data from schoolList3. The find function should apply on that collection only & return the data.

I am unable to solve it that how should I get data without passing schema and did not get any other way.

Upvotes: 0

Views: 643

Answers (1)

Alex Blex
Alex Blex

Reputation: 37128

Set collection name option for your schema from user's input:

var collectionName = 'schoolList3'; // set value from the input 
var dataSchema = new Schema({/** your schema here **/}, { collection: collectionName });

Upvotes: 1

Related Questions