apostrophecms / apostrophe-documentation

Documentation for the ApostroheCMS open-souce ecosystem
https://docs.apostrophecms.org/
MIT License
25 stars 46 forks source link

How to add pieces to mongodb collection or filter pieces? #378

Closed andrewbenrichard closed 3 years ago

andrewbenrichard commented 3 years ago

I want to manipulate pieces but can't find them in my MongoDB collection, how do I do that please

abea commented 3 years ago

What have you tried so far? How are you trying to manipulate pieces in the database and where in the code are you trying to do it? Often that can lead to problems if something is changed that Apostrophe needs. There are ways to do it safely, though.

andrewbenrichard commented 3 years ago

For now, I can't find pieces I added from the site on MongoDB. There are ways to do it safely, though.

There are ways to do it safely, though.

Please what are the recommended methods of doing this

abea commented 3 years ago

The pieces are all in the aposDocs collection. You can find them by their type property. So if it's an article piece type, you could use the { type: 'article'} query.

I still don't know if you are trying to do this from server side code or from the MongoDB CLI, for one thing. This is a good place to start finding more information: https://v2.docs.apostrophecms.org/advanced-topics/database/accessing-the-database-directly.html. Or this, being the safer method: https://v2.docs.apostrophecms.org/advanced-topics/database/cursors.html#an-illustrated-example.

If you are using Apostrophe 3 it works similarly, but we don't have that documented in the V3 docs yet.