java - spring data MongoRepository check if a document exists before inserting by querying with entire document -
java - spring data MongoRepository check if a document exists before inserting by querying with entire document -
i trying create webservice receives json object , performs action based on whether object exists document in mongodb or not. if document exists, have perform action. if doesn't have insert first , perform action.
using spring info mongorepository or mongotemplate, how check if document exists - using entire document insert? cannot utilize _id here. if entire document exists, don't have insert new document. if @ to the lowest degree 1 field different, have come in new document.
eg:
@document (collection = "foo") class foo { @id string id; string name; list<address> address ... many more attributes }
if request using object of foo without _id, how check if exists document in mongodb collection?
thanks!
why don't index collection on field? assuming have name in documents, query db name , if dont result, add together it. if result compare have in request. best thing comparing these 2 override equals
method. convert request body object of document , compare db. if cannot determine passed in request, might have query db based on whatever field passed.
java spring mongodb
Comments
Post a Comment