Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is Find(...).Limit(1).One(...) equivalent to Find(...).One(...) #66

Closed
JordanP opened this issue Dec 6, 2017 · 2 comments
Closed
Assignees
Labels

Comments

@JordanP
Copy link

JordanP commented Dec 6, 2017

Hi,
I tried to answer that question myself but I can't figure out the code exactly. Do you happen to know the answer ?

Thanks !

@domodwyer domodwyer self-assigned this Dec 6, 2017
@domodwyer
Copy link

Hi @JordanP

Yes it is the same - check https://github.com/globalsign/mgo/blob/master/session.go#L3391

Calling One() runs a findCmd with a limit of 1 the same as if you called Limit(1):

expectFindReply := prepareFindOp(socket, &op, 1)
func prepareFindOp(socket *mongoSocket, op *queryOp, limit int32) bool {
	// <snip>

	find := findCmd{
		// <snip>

		Limit: limit,
	}
	
	// <snip>
}

@JordanP
Copy link
Author

JordanP commented Dec 6, 2017

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants