0

What I've understood, sails binds collection with its Models. Is there a way i can create a collection on runtime. What i want to do is create a different collection for each user. something like (user_12345, unique for every user).

I've tried waterline and sails-mongo, They allow me to query collections for CRUD operation. but I couldn't understand how to create a new collection using sails-mongo or waterline library. Please help.

northdakota
  • 3
  • 1
  • 5

1 Answers1

0

Waterline doesn't provide a way to create arbitrary collections in Mongo. The ORM's job is to map the logical models in your app to collections (or tables, or whatever) in your database. It's not clear what you're trying to accomplish by giving each user their own collection, but if it's truly necessary you can still achieve it by just making the raw Mongodb driver a dependency in your project:

npm install --save mongodb

and following the documentation for connecting and creating collections. You won't be able to use Waterline to work with those collections, though; you'll have to use native operations for all inserting, querying, etc.

sgress454
  • 24,870
  • 4
  • 74
  • 92
  • Thank you for replying back. I was using raw mongo driver only to solve my problem. I was just thinking if there could be a better way to fix this. – northdakota Aug 12 '14 at 05:27