Ticket #331 (closed defect: invalid)

Opened 5 years ago

Last modified 5 years ago

Struct creation failure leaves orphan document in collection

Reported by: anonymous Owned by: jaymccarthy
Priority: major Milestone:
Component: jaymccarthy/mongodb.plt Keywords:
Cc: Version: (1 8)
Racket Version:


Consider following code and test case which is defined on a collection with a unique index constraint on global-unique-user-id. The code is designed to test that creation of a second user with same id will fail. The failure does occur, but the second record continues to exist with only the _id field present in it. This does not happen when I try the same test directly in mongo shell.

(define-mongo-struct user "users"

([global-unique-user-id #:required]

[user-profile-data #:set-add #:push]
[profiles #:set-add #:push]
[default-profile #:set-add #:push]
[app-specific-profiles #:set-add #:push]))


"Unique id creation"

(define user?

(λ (x)

(and (mongo-dict? x)

(not (bson-null? (mongo-dict-ref x 'global-unique-user-id))))))

(define auth-handle?

(λ (auth-handle)

(and (equal? (authentication-handle-global-unique-user-id auth-handle) "0000")

(equal? (authentication-handle-auth-handle-type auth-handle) "pxSAN")
(equal? (authentication-handle-auth-handle auth-handle) "me")
(equal? (authentication-handle-auth-credentials auth-handle) "pwd"))))

(let ((user (make-user #:global-unique-user-id "0000")))

(check-pred user? user "User 0000 Created")
(check-equal? (user-global-unique-user-id user) "0000")
(check-exn exn:fail? (make-user #:global-unique-user-id "0000"))
(mongo-collection-remove! (mongo-collection (current-mongo-db) "users") '((global-unique-user-id . 1)))))

Change History

Changed 5 years ago by jaymccarthy

  • status changed from new to closed
  • resolution set to invalid

As far as I can tell, this is not a problem with the binding. If you can show me something it is doing wrong, I'm happy to investigate further. At a glance, it looks like the problem is you are deleting users with id 1 not id "0000", so naturally the second remains. Is that it?

Note: See TracTickets for help on using tickets.