LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Closed Thread
  Search this Thread
Old 01-06-2017, 08:06 AM   #1
istabraq
LQ Newbie
 
Registered: Nov 2016
Posts: 11

Rep: Reputation: Disabled
Question Node.js and MangoDB with collection.update and TTL (Time To Live) not working


Please help, Kindly, how can i used node.js and mongoDB with "collection.update" with TTL (Time To Live) i tried some ideas but it does not work. the first code is mqtt node.js with mongoDB and works fine
Code:
var mqtt = require('mqtt');
var MongoClient = require('mongodb').MongoClient;
var client;
var collection;
var mongodbURI = 'mongodb://localhost:27017/exampleDb4';
var deviceRoot = '#';
var key;

MongoClient.connect(mongodbURI,setupCollection);

function setupCollection(err, db) {
  if(!err) {
    console.log("We are connected");
    collection=db.collection("test_mqtt");
    client  = mqtt.connect('mqtt://192.168.0.132');
    client.subscribe(deviceRoot);

    client.on('message',  function (topic, message) {
    console.log(message.toString());

   key=topic.replace(deviceRoot,'');

   collection.update(
   { _id:key }, 
   { $push: { events: { event: {  value:message, when:new Date() } } } }, 
   { upsert:true },

   function(err,docs) {  
   if(err) {
      console.log("Insert fail")        
       }
                   }
               );
                                                })
       }
                              }
i tried to put this line in the code but it does not work to expire the collections.. Thanks in advance

Code:
b.collection("test_mqtt").createIndex( { "when": 1 }, { expireAfterSeconds: 10 } )
 
Old 01-06-2017, 10:19 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Duplicate reported.
 
Old 01-06-2017, 10:27 AM   #3
istabraq
LQ Newbie
 
Registered: Nov 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Duplicate reported.
i have changed a little bit with my previous question.. and i dont know how to remove the previous one ?
 
  


Closed Thread

Tags
node.js, ttl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TTL modification not working in DDWRT router Littleolme Linux - Networking 13 04-28-2017 04:13 PM
ping with even number ttl always return "Time to live exceeded" yafrank Linux - Networking 4 02-12-2012 02:30 AM
wrong ttl time for dns entries on bind 9.7 with suse 11.4 server marb84 Linux - Networking 4 08-31-2011 04:24 AM
Device Node Change time to time issen007 Linux - General 0 01-22-2010 07:53 AM
LXer: Real-time garbage collection with Real-time Java LXer Syndicated Linux News 0 05-05-2007 12:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration