In this blog , you will find all the MongoDb queries I have used to get data from the interactions table.
---Find all interactions for individual contact ID---
db.getCollection('Interactions').find({ContactId: NUUID("bc0e84d8-f160-de4e-84ad-e701b6581094")})
---Find all interations for a day---
db.Interactions.find({"SaveDateTime":{
'$gte': ISODate("2018-02-20 00:00:01.000Z"),
'$lt': ISODate("2018-02-20 11:59:59.999Z")
}})
---Find all interactions of a day---
db.Interactions.count({"StartDateTime":{$gt: ISODate("2017-03-27T00:00:00:00.000-06:00")}})
---Find all interactions of a day that had single page view---
db.Interactions.find({"StartDateTime":{$gt: ISODate("2017-03-27T00:00:00:00.000-06:00")},"VisitPageCount": 1 })
---Find all interactions of a day that have more than 1 page view ---
db.Interactions.find({"StartDateTime":{$gt: ISODate("2017-03-27T00:00:00:00.000-06:00")},"VisitPageCount": {$gt: 1}})
Datetime query
db.getCollection('Interactions').find({"Pages.DateTime" : ISODate("2018-03-16 05:14:45.272Z")})
Date between
db.getCollection('Interactions').find({"Pages.DateTime" : {
'$gte': ISODate("2018-09-22 00:00:01.000Z"),
'$lt': ISODate("2018-09-22 23:59:59.999Z")
}
, "Pages.Url.Path" :{$regex : "^/api/"}})
Query using regex to search a field
db.getCollection('Interactions').find({"Pages.Url.Path" :{$regex : "^/api/"}})
Multiple queries
db.getCollection('Interactions').count({"Pages.PageEvents.Name" : 'Long running request', "Pages.SitecoreDevice.Name" : 'Default'})
With the below query you can create a new user in MongoDB database.
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)