The object ing in spring-data-MongoDB is through
Mongomappingconverter class. It can be annotated
The document for converting the Java class to MongoDB.
It has the following annotations:
@ ID-Unique Identifier of the document. It is objectid in MongoDB and is unique, consists of Timestamp + machine ID + process ID + auto-increment counter (ensure that IDs generated within the same second do not conflict.
@ Document-declare a Java class as a MongoDB document.
Specify the document corresponding to this class through the collection parameter.
@ Dbref-declares associations similar to relational databases. PS: currently, cascade storage is not supported. When you modify the values in the deref object in this instance, the instance cannot save the objects referenced by deref, it must be saved separately, such as the person and account in the following example.
@ Indexed-declare that this field requires an index. indexing can greatly improve the query efficiency.
@ Compoundindex-composite index statement, composite index can effectively improve the query efficiency of multiple fields.
@ Geospatialindexed-declare this field as an index of geographical information.
@ Transient-the field ignored by the ing. This field is not saved
MongoDB.
@ Persistenceconstructor-declares the constructor to instantiate the data retrieved from the database as an object. The input value of this constructor is the data retrieved from dbobject.
The following is an example of an official document:
Person class
@ Document (Collection = "person") @ compoundindexes ({@ compoundindex (name = "age_idx", Def = "{'lastname': 1, 'age ': -1} ")}) public class person <t extends address >{@ ID private string ID; @ indexed (unique = true) Private integer SSN; private string firstname; @ indexed private string lastname; private integer age; @ transient private integer accounttotal; @ dbref private list <account> accounts; private t address; Public Person (integer SSN) {This. SSN = SSN ;}@ persistenceconstructor public person (integer SSN, string firstname, string lastname, integer age, t address) {This. SSN = SSN; this. firstname = firstname; this. lastname = lastname; this. age = age; this. address = address ;}
Account class
@ Documentpublic class account {@ ID private objectid ID; private float total ;}