0

I'm trying to insert a collection inside a collection. Parent collection has it's name, but sub-collection will have a user-defined name (from a POST request).

I've tried it like this:

newInsert = jotc.newCollection.insert({'some':'data'})

where jotc is the existing parent collection. Instead of replacing newCollection with a value from a variable with the same name, MongoDB created a collection just like that: jotc.newCollection

Mongo version: 2.4.6 PyMongo version: 2.6.2 Python: 2.7.5

1 Answer 1

1

I should have tried a little bit more before posting the question. Solution is to access the 'parent' collection dictionary-style:

newInsert = jotc[newCollection].insert({'some':'data'})

and it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.