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

  • Home
  • SEARCH
  • 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 6933251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:48:31+00:00 2026-05-27T11:48:31+00:00

Here is my CSV file : 12;France;http://www.google.com 12;France;http://www.google.com For each line, the $field[] structure

  • 0

Here is my CSV file :

12;France;http://www.google.com
12;France;http://www.google.com

For each line, the $field[] structure I use to populate my Mongo
object looks like the following :

array(18) {
  ["date_day"]=>  int(12)
  ["url"]=>  string(21) "http://www.google.com"
  ["country"]=>  string(6) "France"
}

For each of these two lines, I call the following :

$result = $coll->update ( array ( 'ts_day' => $field['date_day'] ,'url'=>$field['url']),array('$addToSet' => array ( "countries" => array ( 'name' =>$field['country'] )) ),array ('upsert' => true ));

$result = $coll->update ( array ( 'ts_day' => $field['date_day'] ,'url' => $field['url'] , 'countries.name' => $field['country'] ),array ( '$inc' => array( 'countries.$.views'=> 1) ) ,array ( 'upsert' => true));

I don’t understand why I get an extra { “name” : “France” } object in
the “countries” array, with no “views” counter, although the counter
is properly incremented in countries.france.views (whose value is 2,
which is correct) :

{ "_id" : ObjectId("4eeb0e6cd86450af72f775be"), "url" : "http://www.google.com", "countries" : [ { "name" : "France", "views": 2 }, { "name" : "France" } ], "ts_day" : 12 }

Any idea for this lonely { “name” : “France” } ? Mongo bug or
misunderstanding of mine ?

Thank you !

  • 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-27T11:48:31+00:00Added an answer on May 27, 2026 at 11:48 am

    It sounds like you’re getting too hung up on using the standard mongoimport/export tools to process your CSV files.

    If you check out the source code, you’ll notice that these two tools are rather simple client applications that utilize the MongoDB C++ driver. Were they written in Python or Ruby, they’d like only be 5-10 lines long.

    Why don’t you simply write a new script that reads in the CSV file and inserts the documents in exactly the way you’d like? Want to do aggregation? Do it in client code! Want total control over the schema? You’re set!

    In fact, this would be the best way forward — mongoimport/export is provided for convenience not comprehensiveness. If your data ingestion process requires significantly updating a large number of documents once they’ve already been written to the database, you may even start to see issues with compaction and performance.

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

Sidebar

Related Questions

I have a CSV File here: http://www.filedropper.com/excel which looks like this http://pastebin.com/ammzv4FK . What
I follow the tutorial here to query content from CSV file: http://rudesyle.wordpress.com/2008/01/28/using-linq-to-query-a-csv-file/ However, the
i am reading a csv file line by line here: def GetDistinctValues(theFile, theColumn): lines=theFile.split('\n')
I have a CSV file which uses a highly customized format. Here, each number
I've to parse a problematic CSV file like this: some text here other line
Here is the scenario: I get an CSV file, which has data1, data2, data3,
I'm reading a csv file using c# here is a little code snippet. using
I have a CSV file which has the following format: id,case1,case2,case3 Here is a
I currently have a csv file that I'm parsing with an example from here:
I am trying to read this .csv file and here is an example of

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.