Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

How can I query AEM Data from MongoDB

Avatar

Level 3

I have configured AEM with MongoDB. I wanted to Query MongoDB to fetch AEM data. 

Say I wanted to know list of products for Geometrix Website. OR Say I wanted to know all the users available inside AEM.

Is there any documentation available where I can find out - how to query AEM data from MongoDB, how it is stored and all? 

I wanted to know this because, suppose I wanted to write a Java code to insert data inside MongoDB, for adding some data or displaying some data from AEM. 

Note: I am using MongodbVUE GUI tool to access DB data. 

7 Replies

Avatar

Community Advisor

Yeah you can view all data that used to be under repository folder and know is in your mongo database.

You can use wide range of tools to connect to your database. My choice is RoboMongo :)

However, you should not need to do that since, your access layer ideally is Sling/OAK rather then Mongo and direct search. Depends on your use case ofc.

Avatar

Level 3

RoboMongo is same as MongodbVUE right? But my question is, how can I query? Can you give some sample query or link where it is explained?...

Avatar

Community Advisor

Yes it's similar.

Can't see is being that straight forward, you can start by searching individual fields, added an example that searches for all product under nodes.

Remind you, that some of these fields might be named differently in your database(r14cf0d10fdd-0-1) is likely to have a different name.

Say I wanted to know list of products for Geometrix Website:

db.getCollection('nodes').find({ "cq:template.r14cf0d10fdd-0-1" : /geometrixx-outdoors\/templates\/page_product/})

P.S. it's much easier to execute the same search in AEM6 directly.

Avatar

Level 3

Thanks. Any documentation for the same? or any link?

Wanted to know on what basis this query is formed? How you have build the page say geometrix.../template.../page_product? Is it path in content node (i guess not) Can you please explain the syntax and more details on the same?

Avatar

Community Advisor

Not a single doc I could find that explains how AEM6 stores the jcr data into the MongoDB.

This example is build on the fact that each product page must have a template of certain type in your case:  list of products for Geometrix Website corresponds to  geometrixx-outdoors\/templates\/page_product.

E.g. I am not searching for page I am searching for node with this template.

db.getCollection('nodes').find({ "cq:template.r14cf0d10fdd-0-1" : /geometrixx-outdoors\/templates\/page_product/}) This is how it would look in SQL like language // Select * from nodes // Where cq:template // Like %geometrixx-outdoors/templates/page_product%

Avatar

Level 3

Tried, but not working. Below is what comes in MongoVUE

 

db.nodes.find({ "cq:template.r14d005dce36-0-1" : /geometrixx-outdoors\/templates\/page_product/ }).limit(50);
db.nodes.find({ "cq:template.r14d005dce36-0-1" : /geometrixx-outdoors\/templates\/page_product/ }).limit(50).explain();

 

In MongoVUE after connecting Database I go to Collection\Nodes and then in FIND window I give below Query:

{ "cq:template.r14d005dce36-0-1" : /geometrixx-or14d005dce36-0-1" : /geometrixx-outdoors\/templates\/page_product/ }

I hope I am giving right ID in query. For your ref. below is part of nodes from DB from which I got ref. ID.

/* 0 */
{
  "_id" : "1:/jcr:system",
  "_lastRev" : {
    "r0-0-1" : "r14d00811a13-0-1"
  },
  "jcr:primaryType" : {
    "r14d005dce36-0-1" : "\"nam:rep:system\""
  },
  "_commitRoot" : {
    "r14d005dce36-0-1" : "0"
  },
  "_modified" : NumberLong(1430232570),
  "_deleted" : {
    "r14d005dce36-0-1" : "false"
  },
  "_children" : true,
  "_modCount" : NumberLong(127)
}

Avatar

Administrator

Hi 

Please refer to this forums post:- 

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

//

    You can view all data that used to be under repository folder and know is in your mongo database.

    You can use wide range of tools to connect to your database. My choice is RoboMongo :)

   

Also please have a look this this community article:- http://cq-ops.tumblr.com/post/87307885504/useful-mongodb-commands-for-aem-6

// Useful MongoDB Commands for AEM 6

Documentation :- https://docs.adobe.com/docs/en/aem/6-2/deploy/platform/aem-with-mongodb.html

~kautuk



Kautuk Sahni