Стварэнне парадкавага нумара ў mongoDB (Generating sequence number in mongoDB)


問題描述

Стварэнне парадкавага нумара ў mongoDB (Generating sequence number in mongoDB)

I am using java,Datanucleus,mongodb and JDO in my project.

I have a requirement where I should generate sequence number and store it in DB. I was going through various links and found that  DataNucleus supports the automatic assignment of sequence values for object identities only for the following datastore:‑

Oracle
PostgreSQL
SAP DB
DB2
Firebird
HSQLDB
H2
Derby (from v10.6)
DB4O

So does that mean ‑> sequence generation can't be done for mongoDB? If it can be then please provide some useful link  or guidance !

Note:I am already aware of the fact that mongoDB creates an object id on its own..but I want custom sequence number generation,store it in DB and use it.

‑‑‑‑‑

參考解法

方法 1:

DataNucleus‑MongoDB supports "INCREMENT" value strategy, as stated very clearly in the docs, and additionally supports many other strategies.

(by AbhinavDataNucleus)

參考文件

  1. Generating sequence number in mongoDB (CC BY‑SA 3.0/4.0)

#mongodb-java #java #datanucleus #jdoql #jdo






相關問題

GridFS Java 對像是線程安全的嗎? (Are GridFS Java objects thread safe?)

Драйвер MongoDB Java: такога cmd: aggregate няма (MongoDB Java driver : no such cmd: aggregate)

Стварэнне парадкавага нумара ў mongoDB (Generating sequence number in mongoDB)

MongoDB java驅動如何判斷副本集是否處於自動故障轉移過程中? (How can MongoDB java driver determine if replica set is in the process of automatic failover?)

優化 mongodb 中的查詢 (Optimising queries in mongodb)

查詢數據時應該使用 MongoTemplate 還是 DBCollection (Should i use MongoTemplate or DBCollection when query data)

org.bson.codecs.configuration.CodecConfigurationException:找不到類 [Ljava.lang.String; 的編解碼器; (org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class [Ljava.lang.String;)

如何使用 Java MongoDB 驅動程序檢索字段子集? (How to retrieve a subset of fields using the Java MongoDB driver?)

當使用 karras 和 clojure 給出字段時,如何更新 MongoDB 中的文檔? (How to update a Document in MongoDB when a field is given with karras & clojure?)

如何使用 java 代碼轉換 mongodb 查詢 (How to Transform mongodb query using java code)

MongoDB 文檔使用 Java 中的 findOneAndUpdate 方法更新數組元素 (MongoDB document update array element using findOneAndUpdate method in Java)

aws documentdb 是否為兩種方式的 ssl 驗證 mongodb 客戶端證書? (Does aws documentdb validate mongodb client certificate for two way ssl?)







留言討論