Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7643687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:30:29+00:00 2026-05-31T09:30:29+00:00

NodeJS + Express, MongoDB + Mongoose I have a JSON feed where each record

  • 0

NodeJS + Express, MongoDB + Mongoose

I have a JSON feed where each record has a set of “venue” attributes (things like “venue name” “venue location” “venue phone” etc). I want to create a collection of all venues in the feed — one instance of each venue, no dupes.

I loop through the JSON and test whether the venue exists in my venue collection. If it doesn’t, save it.

jsonObj.events.forEach(function(element, index, array){
    Venue.findOne({'name': element.vname}, function(err,doc){
        if(doc == null){
            var instance = new Venue();
            instance.name = element.vname;
            instance.location = element.location;
            instance.phone = element.vphone;
            instance.save();
        }
    }
}

Desired: A list of all venues (no dupes).

Result: Plenty of dupes in the venue collection.

Basically, the loop created a new Venue record for every record in the JSON feed.

I’m learning Node and its async qualities, so I believe the for loop finishes before even the first save() function finishes — so the if statement is always checking against an empty collection. Console.logging backs this claim up.

I’m not sure how to rework this so that it performs the desired task. I’ve tried caolan’s async module but I can’t get it to help. There’s a good chance I’m using incorrectly.

Thanks so much for pointing me in the right direction — I’ve searched to no avail. If the async module is the right answer, I’d love your help with how to implement it in this specific case.

Thanks again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:30:30+00:00Added an answer on May 31, 2026 at 9:30 am

    Why not go the other way with it? You didn’t say what your persistence layer is, but it looks like mongoose or possibly FastLegS. In either case, you can create a Unique Index on your Name field. Then, you can just try to save anything, and handle the error if it’s a unique index violation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have nodejs application with mongodb(mongoose). like this: var mongoose = require('mongoose'); var express
In my NodeJS express application I have app.js that has a few common routes.
I currently have node.js, express, and mongodb in my heroku environment. What I want
I have built my application using node.js, mongodb, redis, express, socket.io and planning to
I am using node.js with express. I read out data from MongoDB with Mongoose
I have an NodeJS Express app that is getting really big in just one
Using Jade + Express + Node.js + Mongoose + MongoDB for my app, but
I want to rewrite a complete community website in nodejs,express and nowjs with mongodb.
I have a Node.js app using Express that stores data in a mongoDB (locally).
My node.js app uses express, socket.io and talks to mongodb through mongoose. All these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.