Questions tagged [objectid]

The ID of an object. This is used, among other reasons, to refer back to the object at a later time in the program

Used especially in web programming where space on the stack is limited, objectids are used to refer to objects at different parts of the program, and possibly even across different user sessions, if some marshalling is implemented (as databases, etc).

The ID of an object can also be used to determine if two objects are distinct instances or are indeed the same object, in which case, any modifications made on one would be reflected in the other as well

481 questions
4
votes
0 answers

Object#to_s vs __id__ aka object_id

I probably should take a course on using google, but I just can’t find out an answer. When one calls to_s on the instance of class, that does not have an ancestor, overriding to_s, Object#to_s is being called and the output looks…
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
4
votes
1 answer

MongoDB: Can I use a created ObjectId before saving my document

Using mongoose on node.js: Can I access the _id field on a model before it has been saved to the database and be sure that the ID will not change? For example, I would like to do the following: var model = new…
dlebech
  • 1,817
  • 14
  • 27
4
votes
3 answers

native update in Sails with Mongo does not work with ObjectId

I wonder what I am doing wrong. I use Sailsv0.10 and mongo2.6.0 and want to update an array field (using $push) in a collection via native. My model: module.exports = { schema: true, attributes: { username: { type: 'string', required:…
user3707805
  • 105
  • 2
  • 7
4
votes
2 answers

mongo objectid 'contains' query

I would like to query a collection in a MongoDB database to find all records that contain a portion of an ObjectID. For a normal string I can use a regex like this: db.teams.find({"some_string": /^51eed/}) But how would I do something similar on…
rasmeister
  • 1,986
  • 1
  • 13
  • 19
4
votes
1 answer

How can I check the type of object associated with an object_id? (SQL Server 2012)

I've searched through StackOverflow and Google for a while and didn't find anything too similar, so here's my problem: I'm currently writing a stored procedure to check that every every column in a database named 'Sequence' has an associated…
The Boondoggler
  • 105
  • 1
  • 8
4
votes
2 answers

mongodb - Construct DBRef with string or ObjectId

I've noticed that either a string or an object id could be used to construct a DBRef in mongodb. For example db.persons.insert({name: 'alice'}) db.persons.find() // { "_id" : ObjectId("5165419064fada69cef33ea2"), "name" : "alice"…
neuront
  • 9,312
  • 5
  • 42
  • 71
4
votes
1 answer

Query Mongoose Schema by ObjectId

Going to need your help again, hopefully for this project, the answer to what I'm having here will be the last. I've seen it's a fairly commonly asked question, but I've tried the tips on another Stack Overflow post, and one by the Google Group,…
Jester
  • 399
  • 2
  • 3
  • 15
4
votes
3 answers

Passing MongoDB ObjectId in Play Framework URL

Hi I'm learning Play Framework 2 with Java and have a problem. I use MongoDB, and have a simple class User with ObjectId as unique id. public class User { @JsonProperty public ObjectId id; .. in my view I want to add a button to delete…
Dawid
  • 644
  • 1
  • 14
  • 30
4
votes
2 answers

MongoDB How to upsert objects with _id in given Array

My command like this: db.item.remove() db.item.update({_id:{$in:['A1','A2']}},{$inc:{count:1}},{multi: true, upsert: true}) my desired result should be db.item.find() --> {_id: 'A1', count: 1} {_id: 'A2', count: 1} but in fact it is: {_id:…
lonevan
  • 65
  • 1
  • 7
3
votes
4 answers

How create Ruby Class with same object id

I need to create a class where if the attribute value is the same it does not generate a new object id, example: result: described_class.new('01201201202') if i run it again with the same value it…
Davi Luis
  • 396
  • 3
  • 16
3
votes
1 answer

How to type array of mongoose ObjectID in typescript

I'am having an issue with the typing in TypeScript and mongoose schema. I have the following model for a user : export interface IUser extends mongoose.Document { firstname: string; lastname: string; email: string; password?:…
3
votes
1 answer

Is there a way to create an ObjectID from INT in MongoDB?

This question has originally been asked in dba.stackexchange.com. I'm trying to migrate user ids from MySQL to MongoDB and I want to create objectIDs from an int. Is there a way to store INTs inside of ObjectID parts like the random section of…
Alireza
  • 6,497
  • 13
  • 59
  • 132
3
votes
3 answers

What is the nil/zero value of bson.ObjectId

I was creating unary tests when I got stuck on the following situation: I have an object that has a foreign key. For some reason, I need to switch the ID and it works. However, sometimes, I need to remove this ID. If I have an ID, I realise a…
Emixam23
  • 3,854
  • 8
  • 50
  • 107
3
votes
2 answers

How to make a swift Codable struct that will decode and encode a MongoDB _id ObjectId() in JSON

I'm a very new developer(this is my first dev job) building a Swift/iOS application for creating/processing orders, and the server is sending me a ObjectID() object in JSON with every product I look up. After some research, it seems like this is a…
A. L. Strine
  • 611
  • 1
  • 7
  • 23
3
votes
1 answer

Algorithm to generate 12 byte hash from Web URLs

I am crawling some websites for special items and storing them in MongoDB server. To avoid duplicate items, I am using the hash value of the item link. Here is my code to generate the hash from the link: import hashlib from bson.objectid import…
Dipu
  • 6,999
  • 4
  • 31
  • 48