Ground:DB trouble grounding exisiting collection w/ ReactJS

So I have been working on an educational app where I have a collection of roughly 1500 minerals. The idea is I want this data offline 24/7 so the kids can look up the information whenever they want.

Since this is my first app using meteor I followed a couple of tutorials and have the pub/sub working with a collection from the server. I used:

mongoimport -h localhost:3001 --db meteor --collection minerals --type json --file baseDb.json --jsonArray

to load the collection I designed. Now I have been trying to refactor my project to make it so that the db is grounded and can’t seem to get it to work.

For instance in the file imports/api/minerals.js since I am using a simple schema I have the collection exported from there using
export const Minerals = new Meteor.Collection('minerals');

I tried to ground the collection there and export it following the Ground:DB documentation. but i end up inundated by "Uncaught Error: Meteor does not currently support objects other than ObjectID as ids". So I checked the data and it one entry looks like

{ “_id” : ObjectId(“5925e8203945a2236ae2d0cc”), “minName” : “Quetzalcoatlite”,
“summary” : “Named for the feathered snake god, Quetzalcoatl, whom the Toltec and Aztec people believed was the god of the sea, in reference to the minerals sea-blue color. Quetzalcoatlite can be found only at its type locality at the Bambollita Mine at Moctezuma, Mexico, and within the United States in Arizona, California, and Utah. This rare mineral is found in oxidized hydrothermal deposits that contain tellurium.”,
“formula” : “Cu2+3Zn6Te6+2O12(OH)6·(Ag,Pb,[ ])Cl”,
“crystalSystem” : “Hexagonal”,
“crystalHabit” : “”,
“cleavage” : “Distinct, None, None”,
“luster” : “Pearly”,
“color” : “blue”,
“streak” : “Pale blue, almost white”,
“classType” : “Hexagonal - Trapezohedral”,
“fracture” : “Brittle”,
“hardness” : [ 3 ],
“category” : “Oxides” }

I know that the _id was added when I used mongoimport and it looks like the object ID that is needed. I have tried researching this topic but I have had no luck. I came across a lot of topics but I couldn’t find any solutions. I have the feeling the solution is more then just a couple lines of code but rather, that I am missing something in my understanding of collections and the pub/sub architecture (if thats the right description).

My full project is here if anyone is interested in looking at the whole thing.

Any advice/ideas would be much appreciated and if I missed something important in my explanation I will clarify asap. Thank you to anyone in advanced!

It may be something with the data loaded into MongoDB via non-meteor calls (like mongoimport). Export your mongo collection and look at all the exported _id fields. Read this thread for more info: Inserting a composite key gives: "Meteor does not currently support objects other than objectid as ids"

1 Like

Came in to say something similar. We use a microservice to write some stuff into collections and end up using something like this:

// We want string _ids

const data = {
  // our data

const ObjectId = require('mongodb').ObjectId;
data._id =  (new ObjectId).toHexString();


You could probably run an update with something similar, or loop through your data and do inserts with _id values that you generate yourself.

Thank you so much for replying!

@hluz You are so right! although I cannot say I comprehended everything in the thread you posted.
The id came out as:
"_id":{"$oid":"591ba7b1f8f84dc9e4ee5ca4"}, ..."
and if i remember correctly that is not a proper ObjectID right?

And that leads me to @vigorwebsolutions, wouldn’t that approach mean that every time on startup the db has to rewrite the id’s? or do you mean inserting in the meteormongo shell or somewhere else outside of the running application?

I guess I don’t completely understand your use case, but you could probably just have a startup script to look for docs with ObjectIds and run a function to swap them to string ids?

What did the data you loaded looked like? Did it have _id?

@vigorwebsolutions I may not be describing my use case well but the idea is I want a completely offline db, so that when I put the app in the store the db is baked into it. I hope that helps describe my use case at least a little better.

@hluz so this is interesting and I was expecting some of this behavior because of some reading I did here So I thought it wasn’t a problem to load in without an _id. Here is an example of what happens to my data:

Initially in baseDb.json:

{"minName": "Gypsum", "summary": "....", "formula": "CaSO4·2H2O", "crystalSystem": "Monoclinic", "crystalHabit": "...", "cleavage": "Good, Distinct, None", "luster": "Silky", "color": "colorless, white", "streak": "white", "classType": "Prismatic", "fracture": "Conchoidal", "hardness": [2], "category": "Sulfate"},

After using mongoimport, in meteor mongo I use db.minerals.find({minName:'Gypsum}):

{ "_id" : ObjectId("5925e8203945a2236ae2d0b9"), "minName" : "Gypsum", "summary" : ".....", "formula" : "CaSO4·2H2O", "crystalSystem" : "Monoclinic", "crystalHabit" : "....", "cleavage" : "Good, Distinct, None", "luster" : "Silky", "color" : "colorless, white", "streak" : "white", "classType" : "Prismatic", "fracture" : "Conchoidal", "hardness" : [ 2 ], "category" : "Sulfate" }

and I thought that was a proper ObjectId, but then I did what you suggested and exported the data and now the _id has changed yet again:

{ "_id" : { "$oid" : "5925e8203945a2236ae2d0b9" }, "minName" : "Gypsum", "summary" : "....", "formula" : "CaSO4·2H2O", "crystalSystem" : "Monoclinic", "crystalHabit" : "....", "cleavage" : "Good, Distinct, None", "luster" : "Silky", "color" : "colorless, white", "streak" : "white", "classType" : "Prismatic", "fracture" : "Conchoidal", "hardness" : [ 2 ], "category" : "Sulfate" }