Track of new inserted document and execute specific event - javascript

I have a collection of a post when a user comment on a post it will be maintain in an embedded documents of named comments.Now a problem is I have to sent a push notification at every 2 hours like this You have 12 new comments on this post for an owner of this post.
Now after clicking on push notification it redirect me to that comments after seen those comments.Now if a new comments is against post then after 2 hours i will be getting like this You have 3 new comments on this post
You can see in my schema that i will maintain total_comments fields.Problem is how i managed this push notification time based and how to identify and maintain track record of new comments.Should i add some key in schema and write a cron jobs to send push notification
Any help would be appreciated
Here is my record
{
"_id" : ObjectId("57b3aa2db630347c1f9308b4"),
"updated" : ISODate("2016-08-30T05:05:18.301Z"),
"created" : ISODate("2016-08-17T00:05:01.354Z"),
"createdTimeStamp" : 1471392301,
"likes" : [],
"comments" : [
{
"created" : 1471935213,
"user" : ObjectId("57b33c810a56a0a81a9b50b7"),
"text" : "next party",
"_id" : ObjectId("57bbf2edee7a923c156c2f08")
},
{
"created" : 1471935612,
"user" : ObjectId("57b33c810a56a0a81a9b50b7"),
"text" : "its new party ",
"_id" : ObjectId("57bbf47cddd701302ba14fca")
},
{
"created" : 1471935717,
"user" : ObjectId("57b33c810a56a0a81a9b50b7"),
"text" : "its new again",
"_id" : ObjectId("57bbf4e5f934024c275f4f08")
},
],
"total_comments" : 3,
"consumer_id" : ObjectId("57b33c810a56a0a81a9b50b7") // Original User that receive notification
}

There is two way to count new comments I guess.
First :
Storing in your user schema a key lastVisit.
And then do something like db.posts.count({'comments.created': { $gte: $$$YOUR lastVisit$$$ }});
comments.created must become a date.
Second :
Storing a key read: boolean in comments and false by default.
Then every time a user read the notification change this value to true.
And then count the new comments like this db.posts.count({'comments.read': false})
Then I don't know the best choice between a cron task or a setInterval

Related

Need help writing a mongo API query in Javascript(React) that needs info from multiple levels

So I have a collection called "contributors." Within that collection the objects look like this:
{
"_id" : ObjectId("5ef1f75f7e6fb579ed3e5e8a"),
"#attributes" : {
"cand_name" : "name",
"cid" : "",
"cycle" : "",
"origin" : "",
"source" : "",
"notice" : ""
},
"contributor" : [
{
"#attributes" : {
"org_name" : "National Beer Wholesalers Assn",
"total" : "20000",
"pacs" : "20000",
"indivs" : "0"
}
},
{
"#attributes" : {
"org_name" : "Alabama Power",
"total" : "15000",
"pacs" : "10000",
"indivs" : "5000"
}
},
... with 10 "#attributes" objects in the "contributor" array.
What I need to do is query this whole collection to find each cand_name object that includes a certain org_name, which I'm already uncertain of how to do (since every time I've tried to query with a string it replaces the spaces in my string with %20).
But then I need to display a table with all the cand_name objects that included that org_name with the total, pacs, and indivs numbers that correspond to that cand_name & org_name.
To be super clear here I'm trying to make a table that displays every politician that a company has given money to (and how much).
So through all this I'm looking in multiple levels of each object and need to display data from all those levels together in one table. I may just be overthinking this, but it seems like it's going to be a complicated query...
Help?
Figured this out! Ended up working with the backend guy on our project and he did it all on backend.

Sending the result of a mongoDB view to another collection ( INSERT....SELECT from SQL )

I could create a big query, and turn it into a view. Let's call it DBA_VIEW.
db.DBA_VIEW.find()
I'm using noSQLbooster to interact with mongodb and I'm trying to insert the result of this view into another collection.
I don't want to "right click > export" because I need to do this via noSQLbooster itself.
I've seen some querie sthat can do the trick, but, as a SQL SERVER dba, I think I can't get the logic behind, let's say, this one below:
db.full_set.find({date:"20120105"}).forEach(function(doc){
db.subset.insert(doc);
});
how can I use such approach to do my taks?
I just need the result of that view from a collection, to be inserted in another collection, then after this we are going to export the data into a .json file or even a .TXT.
You can design the query in the following way so that the output is directly inserted in a new collection('subset' in this example) without iterating through the result set.
db.full_set.aggregate([
{
$match:{
"date":"20120105"
}
},
{
$out:"subset"
}
])
If 'full_set' has the following documents:
{
"_id" : ObjectId("5d423675bd542251420b6b8e"),
"date" : "20130105",
"name" : "Mechanic1"
}
{
"_id" : ObjectId("5d423675bd542251420b6b8f"),
"date" : "20120105",
"name" : "Mechanic2"
}
{
"_id" : ObjectId("5d423675bd542251420b6b90"),
"date" : "20120105",
"name" : "Mechanic3"
}
With the above query, the 'subset' collection would be having the following documents:
{
"_id" : ObjectId("5d423675bd542251420b6b8f"),
"date" : "20120105",
"name" : "Mechanic2"
}
{
"_id" : ObjectId("5d423675bd542251420b6b90"),
"date" : "20120105",
"name" : "Mechanic3"
}

Is there a way to check for duplicate entries in values of an array in MongoDB?

I am trying to remove the duplicate values from a deeply nested array. I've put the structure of the database down below. I want to compare the location of the steps with eachother and check for duplicates. I was thinking about using db.collection.aggregate, but it becomes a problem when trying to search through all steps since { $unwind: '$mapbox.routes.legs.0.steps' } requires a specific index for the steps as far as i know.
"mapboxRoute" : {
"routes" : [
{
"distance" : 105375,
"duration" : 8261.3,
"weight" : 11365.5,
"weight_name" : "routability",
"geometry" : "iv||H_{f^w#b#AFDZHb#DTBL?B#LN`ALx#BPA#WPEBc#X[PIFADFb#T|AHd#DZL~##DF\\Hd#DVFVBPDL?BBL#DBFJb#FV?#BHDL#FKBa#`#MJx#y##FKBa#`#MJi#b#WN]ROLSPWkAFS#s#Mg#Lf#Ar#GRVjAIHKJ_#b#INEFI^CHMPA#]\\IFa#\\s#l#MJMLIHe#b#_#^w#j#KFEBk#d#EDEDEBEBEBKJKHEBMLIHEDQDQLGFMHTQGFMHq#d#e#^GFg#b#ABQNCBIFWRQNm#h#QNa#\\ONGF?FAZBJv#vDd#xBd#fBj#hA`A`Cf#lAz#xBd#r#Z\\PRE\\CXCPB`A?r#A|#EdAR?DqABmDC]Ge#Me#m#yA}#wBiBeEo#uAg#cBMa#oAgGAKOU{AnAIFKJNRNMnAeABJNt#BNb#pBb#tB#BH\\ZhADF\\p#FN`A`Cf#lAHTFLDNb#dALRV^BBVXWYVZRPLHHDHDHDJCRCLAPG~#UNGLEDCRGPGJEl#UJEREBAVA\\BLBHF##PPHJJJNPBDFLBBL^Qc#BBL`#DJBDHPDPHNDJHPFJ#BBDPRPRNNRPBBHFNPDJP\\BDNf##D`BlHHTBLP^T^BBRVFFDBVLj#VLF~#b#FBGCHDJDB#ZJJF`#PTJNJZN^ZJHVVRTFJRVr#bAHJf#v#DFDF#BJL`#n#l#~#RXT^T\\f#t#FH##LRLRjAjB`#r#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Z??H`#?#DT??BL???B#LN`A??Lx#??BP",
"name" : "Mariaplaats",
"ref" : null,
"destinations" : null,
"exits" : null,
"driving_side" : "right",
"mode" : "driving",
"maneuver" : {
"location" : [
5.117934,
52.089493
]
Does someone know how I can compare the locations of the steps?
At the end I stopped making a seperate file for connecting with mongodb and cleaning the database and started using the already existing API to create a call. In this call I looped through the steps in the database and mapped the location to a key. After that I check if that key already existed and pushed that index to a duplicate array.
Then I proceeded to loop through the duplicate list and spliced the duplicate entries from the list with steps. After that I ran the following function to update the entry: await routeSchema.updateOne({ _id: route._id }, { $set: route });

Meteor Mongo not working but standalone MongoDB is

I have the following document
{
"_id" : ObjectId("5464e68481f8252e74f6e0ef"),
"message" : "Hello World!",
"timestamp" : ISODate("2014-11-13T17:12:36.547Z"),
"sender" : "D3EkLv8vatX3xfCGE",
"receiver" : [
{
"id" : "YzhZchz4AwCAd3q2R",
"seen" : false
},
{
"id" : "sm2W28EKYmHz29Aoj",
"seen" : false
}
],
"saved" : false
}
That's the basic structure. Now I want to get all the documents that have the current user's ID. The id can be in the sender field or one of the object in the receiver array. This works fine:
db.messages.find({ sender: "D3EkLv8vatX3xfCGE" })
But the following query doesn't work on the Meteor Mongo instance but does so in Mongo 2.6:
db.messages.find({ receiver: {id: "YzhZchz4AwCAd3q2R"} })
Is there any way I can get this to work. Also, the above query works on Minimongo but doesn't work on Meteor's bundled mongo(meteor mongo) which is currently at v2.4.9.
On mongo shell this query seems to work:
db.messages.find({ "receiver.id": "YzhZchz4AwCAd3q2R"} )
You can find all of the documents were a particular user is a receiver using receiver.id in your selector like so:
Messages.find({'receiver.id': 'YzhZchz4AwCAd3q2R'})
If you wanted to find all documents where a particular user was either a receiver or a sender you could do this:
var id = 'YzhZchz4AwCAd3q2R';
Messages.find({$or: [{'receiver.id': id}, {sender: id}]});

User data structure with Firebase

I asked several times and nobody gives me proper answer. So in Firebase, is this the proper data structure?
{
"users" : {
"-JNNJ-0ErS6kX5AFkfM3" : {
"userUid" : "simplelogin:66",
"userId" : "66",
"email" : "fd2#sdsa.cz"
}
"accounts" : {
"-JLXe5iaH-TLSBu0RJqp" : {
"currency" : "-JLXe--zoxk1DdKa9mAT",
"description" : "account1",
"name" : "account1"
},
"-JNJdqZouwAfEzmCSHTO" : {
"description" : "asdasd",
"name" : "dsad"
},
"-JLgcjINbZni6luTuPSY" : {
"currency" : "-JLXe--zoxk1DdKa9mAT",
"description" : "fefef",
"name" : "bkkjsdds"
}
},
"categories" : {
"-JLgd4W8COP6zOlhNdq9" : {
"color" : "#c55353",
"account" : "-JLXe5iaH-TLSBu0RJqp",
"description" : "fds",
"name" : "dsfdsfds"
}
},
"records" : {
"-JNNK2hnJ99dZqRmfsjs" : {
"date" : "2005-09-28T10:48",
"amount" : 123,
"description" : "description",
"category" : "-JLgd4W8COP6zOlhNdq9"
}
}
},
}
If it's hard to read, there is explanation.
I have a user with a key. User has accounts > every account has categories (every category has a key from an account) > every category has records (every record has a key from a category.
So for example that one record (I am describing parameters):
record's key: -JNNK2hnJ99dZqRmfsjs
records belongs to category with the key: -JLgd4W8COP6zOlhNdq9
People from Firebase unfortunately didn't help me at all and I don't understand their single tutorial.
Is this the proper way to do so? I just want to have data for each user (nobody else can't see another user's data).
EDIT:
Is this correct? I know that post. But I still don't understand it.
In real world is this proper way?
users
-JNNK2hnJ99dZqRmfsjs (key of user1 for example)
name
id
etc
accounts
-JLgd4W8COP6zOlhNdq9 (key of some account)
name
description
-KFTf6W8COP6zOlhNdq9 (key of user - account belongs to user and account has users reference - the key)
Is this correct?
EDIT2:
Look at this:
awesome.firebaseio-demo.com
Anant has beautiful tree:
users
user1
name
user2
name
How did he do it? I thought I can work only with keys.
Firebase blog post - Denormalizing Your Data is Normal helps you with proper data structure.
The second question ("nobody else can't see another user's data) is about security rules - you have to determine who can read data.

Categories