by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 19 20:05
    @krisb1220 banned @Gastony
  • May 14 22:39
    @bjorno43 banned @minitechtips_twitter
  • May 14 22:38
    @bjorno43 banned @real-action
  • Feb 01 00:26
    @bjorno43 banned @Ndoua
  • Jan 07 03:10
    @bjorno43 banned @doctor-sam
  • Aug 17 2019 09:32
    User @bjorno43 unbanned @linkin-park
  • Aug 17 2019 01:43
    @bjorno43 banned @linkin-park
  • Jun 20 2019 21:20
    @bjorno43 banned @shenerd140
  • May 10 2019 09:13
    @bjorno43 banned @zhaokunhaoa
  • Apr 27 2019 19:47
    @mstellaluna banned @zhonghuacx
  • Apr 25 2019 17:12
    @mstellaluna banned @cmal
  • Jan 08 2019 22:00
    @mstellaluna banned @dertiuss323
  • Dec 15 2018 23:36
    @mstellaluna banned @18835579411
  • Dec 13 2018 23:57
    @mstellaluna banned @brandon6190
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:13
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
Nathan
@natertot12
Can someone help me. How do I search for something thats not in an array for mongoDB.
db.collection('polls').findOne({
        _id: ObjectID(currentPoll),
        //votedBy: {$nin: currentUser._id },
        votedBy: {$not: currentUser._id}
    },function(err, poll) {
        if(err) throw err;
        if(poll != null) {
//do code below
Andre Alonzo
@paycoguy
@natertot12 see if this works
Nathan
@natertot12
@paycoguy I tried that but it still doesn't work... Maybe its my update function
db.collection('polls').update({
          _id: ObjectID(currentPoll)
      }, { 
          $push: { votedBy: currentUser._id } 
      });
I've also tried $addToSet
Mateo Pool
@IAmMyself
On learnyounode HTTP CLIENT (Exercise 7 of 13), it says "For this exercise you will need to use the http core module. " How do I do that?
Andre Alonzo
@paycoguy
@natertot12 are you looking inside your mongodb to see if your update works properly?
Nathan
@natertot12
@IAmMyself npm install -g http``http = require("http")
Mateo Pool
@IAmMyself
does this go in the bash terminal?
@natertot12
Nathan
@natertot12
@paycoguy I've console.log(poll.votedBy) after my if(poll != null) and it returns empty
Andre Alonzo
@paycoguy
@natertot12 you can log into mongodb to verify that the update worked
Nathan
@natertot12
@IAmMyself Yeah first do npm install -g http in terminal and at the top of your learnyounodefile.js say var http = require("http") then you can just call http.createServer or whatever
Mateo Pool
@IAmMyself
@natertot12 Thx
CamperBot
@camperbot
iammyself sends brownie points to @natertot12 :sparkles: :thumbsup: :sparkles:
:star: 344 | @natertot12 | http://www.freecodecamp.com/natertot12
Andre Alonzo
@paycoguy
in a terminal type
mongo
then
use <database name>
then
db.polls.find({})
Nathan
@natertot12
@paycoguy Ok one min
@paycoguy How should I check my update function?
Andre Alonzo
@paycoguy
@natertot12 run then function, then go to your terminal and do a db.polls.find({})
find the poll in question and see if the user was added to the poll
CamperBot
@camperbot
find the poll in question and see if the user was added to the poll
nothing found
Nathan
@natertot12
@paycoguy With $nin It returns
MongoError: Can't canonicalize query: BadValue $nin needs an array
Andre Alonzo
@paycoguy
@natertot12 when you do a db.polls.find({}), is votedBy an array?
Nathan
@natertot12
Yeah but its empty
function savePoll(des, chart) {
    var polls = db.collection('polls');
    polls.insertOne({createdBy: currentUser._id.toString(), total: 0, "Description": des, "Data": chart, votedBy: []}, function(err) {
      if(err) throw err;
    });
  }
Andre Alonzo
@paycoguy
@natertot12 ok so that means that the update isn't working
@natertot12
db.collection('polls').update({
          _id: ObjectID(currentPoll)
      }, { 
          $push: { votedBy: currentUser._id } 
      });
shouldn't this be
db.collection('polls').update({
          _id: ObjectID(currentPoll._id)
      }, { 
          $push: { votedBy: currentUser._id } 
      });
I changed _id: ObjectID(currentPoll) to _id: ObjectID(currentPoll._id)
Nathan
@natertot12
I'm saving currentPoll only as a string its the url if someone goes to /polls/:specificpoll
But its only the :specificpoll part
Andre Alonzo
@paycoguy
@natertot12 :specificpoll is supposed to be the _id of the poll?
Nathan
@natertot12
@paycoguy Yeah this is what it looks like http://timestamp-natertot12.c9users.io:8080/polls/56ccd1b7ad095500101b945f
Andre Alonzo
@paycoguy
@natertot12 I'm not really sure what's going one. You can try adding this callback to the update function to get more information.
db.collection('polls').update({
          _id: ObjectID(currentPoll)
      }, { 
          $push: { votedBy: currentUser._id } 
      }, function(err, result){
       if(err){
          console.log(err);
       }
       console.log(result);
      });
Drew Sartorius
@DuckyDisciple
I'm trying to get socket.io set up in my cloud9 environment. From what it looks like in the documentation, a socket.io folder is supposed to be created. I don't have that folder created. Is there something I am missing, or is there something special I need to do for c9?
Nathan
@natertot12

@paycoguy Ok I may have figured it out it returns this:

{ [MongoError: failing update: objects in a capped ns cannot grow]
  name: 'MongoError',
  message: 'failing update: objects in a capped ns cannot grow',
  driver: true,
  index: 0,
  code: 10003,
  errmsg: 'failing update: objects in a capped ns cannot grow' }
undefined

So how do I uncap it?

@DuckyDisciple I've used http://socket.io/docs/#using-with-express-3/4 and It works fine on c9 without a folder
Andre Alonzo
@paycoguy
@natertot12 hmm never seen that error before.
I'm reading this https://docs.mongodb.org/manual/core/capped-collections/
Drew Sartorius
@DuckyDisciple
@natertot12 Did you have to manually copy files over from somewhere?
Andre Alonzo
@paycoguy
@natertot12 are you explicitly creating the polls collection?
Nathan
@natertot12

@paycoguy At the top of my server.js I had

db.createCollection("polls", {
        capped: true,
        size: 5242880,
        max: 5000
    });

Should I delete my MongoDB database and make a new one?

Andre Alonzo
@paycoguy
@natertot12 ah ok. you don't need to create the polls collection explicitly with mongodb. you can get rid of that line and then delete your DB
when you do an update, it'll automatically create the polls collection if it doesn't exist.
Nathan
@natertot12
@DuckyDisciple No I only used Socket.Io for client to server so I basically just copied and pasted their code in my server.js and .html
@paycoguy Ok I didn't know that let me try
Drew Sartorius
@DuckyDisciple
When I put in their code and change the default path for the socket.io.js file to the one I copied, it looks like it keeps failing because it is pointing to https://myurl/socket.io/ but that path doesn't exist.
Nathan
@natertot12
@paycoguy I still get
MongoError: Can't canonicalize query: BadValue $nin needs an array
But when I run the console.log(result) instead it doesn't return any errors
@DuckyDisciple I used
var socket = io.connect('http://timestamp-natertot12.c9users.io:8080/');