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
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/');
so just paste in your c9 url with port
thats in my html
Andre Alonzo
@paycoguy
@natertot12 when you go into your mongo terminal, do you see an array of userids in the votedBy field?
Drew Sartorius
@DuckyDisciple
@natertot12 Yeah, that's what I put in. When I load that page up, I get a bunch of errors pointing to that path with /socket.io/ added on to the end and it's giving me a 404
Nathan
@natertot12
@paycoguy Its empty right now, do I have to add a userid for it to think its an array?
@DuckyDisciple Make sure your <script> is this
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
That way you don't have to install it locally
Andre Alonzo
@paycoguy
@natertot12 not sure. you can try not specifying that votedBy is an array when you save the poll
@paycoguy you can also try the $not operator instead. seems like people are having issues with $in and $nin.
so something like this
function savePoll(des, chart) {
    var polls = db.collection('polls');
    polls.insertOne({createdBy: currentUser._id.toString(), total: 0, "Description": des, "Data": chart}, function(err) {
      if(err) throw err;
    });
  }
mongo will create the votedBy field when you do an update or add. You don't need to initialize it.
Nathan
@natertot12
@paycoguy Ok, I took away the votedBy and when I used $nin I got the same error as before and when I used $not I got
MongoError: Can't canonicalize query: BadValue $not needs a regex or a document
Andre Alonzo
@paycoguy
@natertot12 here try this
db.collection('polls').findOne({
        _id: ObjectID(currentPoll),
        votedBy: {$nin: [currentUser._id] }
    },function(err, poll) {
        if(err) throw err;
        if(poll != null) {