<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:55:57 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-1068] unique indexes not enforced within array of single document</title>
                <link>https://jira.mongodb.org/browse/SERVER-1068</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I am finding that a unique index is not applied to multiple elements of an array in the same document of a collection. They are only applied between documents in a collection.&lt;/p&gt;

&lt;p&gt;More details available at: &lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/56bf4f84f7cad835&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/56bf4f84f7cad835&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is this intended behavior? Is there a way around it?&lt;/p&gt;</description>
                <environment>linux</environment>
        <key id="11866">SERVER-1068</key>
            <summary>unique indexes not enforced within array of single document</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="backlog-query-optimization">Backlog - Query Optimization</assignee>
                                    <reporter username="wwwes">Wes</reporter>
                        <labels>
                            <label>index-version</label>
                    </labels>
                <created>Fri, 30 Apr 2010 01:33:38 +0000</created>
                <updated>Tue, 6 Dec 2022 05:49:32 +0000</updated>
                                            <version>1.4.0</version>
                                                    <component>Index Maintenance</component>
                                        <votes>91</votes>
                                    <watches>85</watches>
                                                                                                                <comments>
                            <comment id="3195941" author="asya" created="Mon, 8 Jun 2020 20:55:58 +0000"  >&lt;p&gt;There is a workaround to prevent such duplicates using &lt;a href=&quot;https://docs.mongodb.com/manual/core/schema-validation/#other-query-expressions&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;document validation&lt;/a&gt;. You have to create a rule (aka query) that will accept only documents which don&apos;t have duplicate values within the same array, and then rely on the unique index to ensure that there are no duplicates across separate documents like before.&lt;/p&gt;

&lt;p&gt;Here is an example validator where &lt;tt&gt;&quot;a&quot;&lt;/tt&gt; is an array and within &lt;tt&gt;&quot;a&quot;&lt;/tt&gt; subdocument field &lt;tt&gt;&quot;b&quot;&lt;/tt&gt; value must be unique. This assumes the collection is either empty or already complies with the rule:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.coll.createIndex({&quot;a.b&quot;:1},{unique:true})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;/* validate that incoming documents have as many unique &quot;a.b&quot; values as total &quot;a.b&quot; values */&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.runCommand({collMod:&quot;coll&quot;, validator: {$expr:{$eq:[{$size:&quot;$a.b&quot;},{$size:{$setUnion:&quot;$a.b&quot;}}]}}})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;/* test it */&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.coll.insert({a:[{b:1}]}) /* success */&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.coll.update({},{ &apos;$push&apos; : { &apos;a&apos;:{b:1}}})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;WriteResult({&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	&quot;nMatched&quot; : 0,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	&quot;nUpserted&quot; : 0,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	&quot;nModified&quot; : 0,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	&quot;writeError&quot; : {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;		&quot;code&quot; : 121,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;		&quot;errmsg&quot; : &quot;Document failed validation&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&amp;gt; db.coll.insert({a:[{b:5},{b:5,c:11}]})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;WriteResult({&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	&quot;nInserted&quot; : 0,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	&quot;writeError&quot; : {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;		&quot;code&quot; : 121,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;		&quot;errmsg&quot; : &quot;Document failed validation&quot;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;	}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;Note that this validator assumes that &lt;tt&gt;&quot;a&quot;&lt;/tt&gt; will always be an array. If &lt;tt&gt;&quot;a&quot;&lt;/tt&gt; is allowed to be a single document then change the validator to&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;validator:{$or:[{a:{$not:{$type:&quot;array&quot;}}},{$expr:{$eq:[{$size:&quot;$a.b&quot;},{$size:{$setUnion:&quot;$a.b&quot;}}]}}]}})&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;meaning &lt;tt&gt;&quot;a&quot;&lt;/tt&gt; can be a non-array type &lt;b&gt;OR&lt;/b&gt; an array where &lt;tt&gt;&quot;b&quot;&lt;/tt&gt; is not duplicated.&lt;/p&gt;

&lt;p&gt;Please note that until &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-20547&quot; title=&quot;Expose the reason an operation fails document validation&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-20547&quot;&gt;&lt;del&gt;SERVER-20547&lt;/del&gt;&lt;/a&gt; is resolved, the error on failing validation (as you can see above) will just be &quot;Document failed validation&quot; so if there are other validations that are done via this method, it may be ambiguous why the document failed.   Document validation is available since MongoDB 3.2.&lt;/p&gt;</comment>
                            <comment id="3105196" author="prateek.ashtikar512@gmail.com" created="Sun, 24 May 2020 10:31:59 +0000"  >&lt;p&gt;@All - Could you please update on this issue ? Or if fixed already, can anyone please suggest to apply index or compound index ?&lt;/p&gt;

&lt;p&gt;Anxiously awaiting for response. Please do the needful.&lt;/p&gt;</comment>
                            <comment id="2595107" author="mazgo.wissem@gmail.com" created="Mon, 9 Dec 2019 23:56:40 +0000"  >&lt;p&gt;80 votes, still not enough ?&lt;/p&gt;</comment>
                            <comment id="2527834" author="iamacoderguy@gmail.com" created="Mon, 11 Nov 2019 13:15:42 +0000"  >&lt;p&gt;How many votes to have this one implemented?&lt;/p&gt;</comment>
                            <comment id="2248144" author="blakewest" created="Wed, 15 May 2019 21:50:00 +0000"  >&lt;p&gt;Yes! We&apos;d love this too. This just caused financial bugs on our side, because this is highly unexpected behavior.&lt;/p&gt;</comment>
                            <comment id="2073949" author="sudhanshu94" created="Wed, 28 Nov 2018 13:57:02 +0000"  >&lt;p&gt;Is there any Updates till now, Please fix this I am really waiting for a fix &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                            <comment id="1884835" author="asya" created="Mon, 7 May 2018 16:59:12 +0000"  >&lt;p&gt;For arrays of scalars or cases where entire subdocument must be unique, $jsonSchema (available in 3.6.0) allows constraining that all array elements must be unique.&lt;/p&gt;

&lt;p&gt;This does not resolve the case where a single field of the subdocument of an array must be unique so this ticket is still relevant to tracking that.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="1492029" author="tony-kerz" created="Fri, 3 Feb 2017 20:46:19 +0000"  >&lt;p&gt;i just came up against this, and it is resulting in a non-trivial amount of effort to enforce this at the application level. gotta say, the fact that there are almost 60 votes for this issue, half a dozen stack overflow type posts, and it has been sitting here for 7 years after Eliot stated &quot;its mostly clear its a bug&quot;, kind of makes me sad.&lt;/p&gt;</comment>
                            <comment id="1411111" author="cameron.stitt@simplehq.co" created="Tue, 18 Oct 2016 03:22:06 +0000"  >&lt;p&gt;Again, any movement on this? I will have to re-architect my solution to go across multiple collections (which would then argue why use mongo) rather than have the ability for intra-document uniqueness.&lt;/p&gt;</comment>
                            <comment id="1216306" author="bawongfai" created="Sun, 27 Mar 2016 16:54:45 +0000"  >&lt;p&gt;Is there any update for this bug?&lt;/p&gt;</comment>
                            <comment id="957796" author="psi29a" created="Fri, 3 Jul 2015 16:51:45 +0000"  >&lt;p&gt;Any movement on this? &lt;/p&gt;</comment>
                            <comment id="291791" author="dhubler" created="Mon, 18 Mar 2013 08:47:04 +0000"  >&lt;p&gt;I was able to use a workaround, you can &quot;normalize&quot; the data&lt;/p&gt;

&lt;p&gt;$db.bar.find()&lt;br/&gt;
 {_id: 10, foo: 1, b:1}&lt;br/&gt;
 {_id: 11, foo: 1, b:2}&lt;br/&gt;
 {_id: 12, foo: 1, b:3}&lt;/p&gt;

&lt;p&gt;$db.foo.find()&lt;br/&gt;
 {_id: 1, bar:&lt;span class=&quot;error&quot;&gt;&amp;#91;10,11,12&amp;#93;&lt;/span&gt;}&lt;/p&gt;

&lt;p&gt;Then you can &lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;use $addToSet on foo.bar to manage unique items&lt;/li&gt;
	&lt;li&gt;add compound key bar 
{foo,b}
&lt;p&gt; to restrict duplicates&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;use upsert on bar collection to easily add new items or update existing ones. trick is to read the return from the upsert use that in the $addToSet operation on foo&lt;/li&gt;
&lt;/ul&gt;
</comment>
                            <comment id="285117" author="ethangarofolo" created="Sat, 9 Mar 2013 12:59:54 +0000"  >&lt;p&gt;+1 for the issue and for either of Joe&apos;s solutions.  Those both feel very natural.&lt;/p&gt;</comment>
                            <comment id="178969" author="jgornick" created="Thu, 25 Oct 2012 06:40:31 +0000"  >&lt;p&gt;I wrote a post about unique indexes @ &lt;a href=&quot;http://joegornick.com/2012/10/25/mongodb-unique-indexes-on-single-embedded-documents/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://joegornick.com/2012/10/25/mongodb-unique-indexes-on-single-embedded-documents/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also have some proposed solutions for declaring single document unique indexes and would love to get some feedback!&lt;/p&gt;</comment>
                            <comment id="103069" author="jesse" created="Fri, 23 Mar 2012 19:06:04 +0000"  >&lt;p&gt;Also, it seems this should fail but doesn&apos;t:&lt;/p&gt;

&lt;p&gt;db.foo.insert({a:[&lt;/p&gt;
{b:1}
&lt;p&gt;, &lt;/p&gt;
{b:1}
&lt;p&gt;]})&lt;/p&gt;</comment>
                            <comment id="90793" author="tzury" created="Wed, 22 Feb 2012 11:59:56 +0000"  >&lt;p&gt;Wasn&apos;t aware of this ticket, there is a small thread on this at stack-overflow. &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://stackoverflow.com/questions/9390590/mongodb-indexing-embedded-fields-dot-notation&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://stackoverflow.com/questions/9390590/mongodb-indexing-embedded-fields-dot-notation&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="37440" author="eliot" created="Tue, 14 Jun 2011 04:22:30 +0000"  >&lt;p&gt;Its mostly clear its a bug, though its a little odd.&lt;br/&gt;
Unique indexes are designed to enforce only 1 document has that key.&lt;br/&gt;
Technically, that&apos;s true for this case, but in the way most people use the feature, they want unique to include the subdocs.&lt;/p&gt;

&lt;p&gt;Pretty big semantic change, so not sure we can squeeze in 1.9&lt;/p&gt;</comment>
                            <comment id="36746" author="mattalbright" created="Wed, 8 Jun 2011 18:11:07 +0000"  >&lt;p&gt;This seems to me to be a pretty clear cut bug... why is it labeled a &quot;question&quot;? &lt;/p&gt;

&lt;p&gt;If you&apos;re moving from a two table relational model of 1:N, and embedding the &apos;N&apos; documents inside of each parent document in Mongo, you want to ensure the id&apos;s of all those child documents don&apos;t collide: both across parent documents as well as within one.&lt;/p&gt;

&lt;p&gt;I&apos;m trying to do just this, and this bug is going to require me to add some nasty hack to enforce uniqueness... and I&apos;ll probably still have to deal with a possible race condition.&lt;/p&gt;

&lt;p&gt;Any chance of getting this into 1.9?&lt;/p&gt;</comment>
                            <comment id="30043" author="jp777" created="Thu, 28 Apr 2011 06:15:11 +0000"  >&lt;p&gt;I have need for this exact situation as described by db.foo.ensureIndex(...) above.  Since the index is a separate collection I could see the server code checking for the existence of the pair in the index prior to making attempts to append to the array.  &lt;/p&gt;

&lt;p&gt;Otherwise, I have to make an initialize search for every element to see if the document exists having those subdocuments.  I have found in the past using SQL databases that it can be more efficient to simply perform an INSERT, have the INSERT fail on the server side, respond to or ignore the error on the client and move on.  This obviously is for write only situations and assumes you do not want to update that previously inserted record.  Regardless, you still need the index across the subdoc so might as well have it enforce unique and save one round trip.&lt;/p&gt;

&lt;p&gt;This can be much more efficient than having to select each time to see if a subdoc record exists prior to inserting one.  This can be a huge performance main in my situation.&lt;/p&gt;

&lt;p&gt;Cheers&lt;/p&gt;</comment>
                            <comment id="19240" author="betawarz" created="Fri, 15 Oct 2010 20:25:46 +0000"  >&lt;p&gt;I just ran across this scenario, too. I do not know about the complexities involved in adding this functionality, but this would be very helpful to me.&lt;/p&gt;</comment>
                            <comment id="13976" author="eliot" created="Mon, 3 May 2010 14:35:00 +0000"  >&lt;p&gt;from &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-1069&quot; title=&quot;Enforcing unique values within a document &quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-1069&quot;&gt;&lt;del&gt;SERVER-1069&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Should it be possible to enforce uniqueness of an object within an array within a single document using a unique index?&lt;/p&gt;

&lt;p&gt;For instance:&lt;/p&gt;

&lt;p&gt;db.foo.save( { a : [ &lt;/p&gt;
{ b : 1 }
&lt;p&gt; ] } )&lt;br/&gt;
db.foo.ensureIndex({_id: 1, &apos;a.b&apos;: 1}, &lt;/p&gt;
{unique: true}
&lt;p&gt;);&lt;/p&gt;

&lt;p&gt;// This succeeds. Should it fail?&lt;br/&gt;
db.foo.update({}, { &apos;$push&apos; : { &apos;a&apos;: &lt;/p&gt;
{b: 1}
&lt;p&gt; } });&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                                                <inwardlinks description="is depended on by">
                                                        </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_12751" key="com.atlassian.jira.plugin.system.customfieldtypes:multiselect">
                        <customfieldname>Assigned Teams</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="25126"><![CDATA[Query Optimization]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_13552" key="com.go2group.jira.plugin.crm:crm_generic_field">
                        <customfieldname>Case</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[[500A000000YPu1DIAT, 5002K00000e8A5YQAU, 5002K00000hQcbqQAC, 5002K00000uE87zQAC, 5002K00000vdgC7QAI, 5006R00001onpyXQAQ]]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 3 May 2010 14:35:00 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        3 years, 35 weeks, 2 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>alexander.golin@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            3 years, 35 weeks, 2 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>jesse@mongodb.com</customfieldvalue>
            <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>backlog-query-optimization</customfieldvalue>
            <customfieldvalue>blakewest</customfieldvalue>
            <customfieldvalue>psi29a</customfieldvalue>
            <customfieldvalue>cameron.stitt@simplehq.co</customfieldvalue>
            <customfieldvalue>dhubler</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>ethangarofolo</customfieldvalue>
            <customfieldvalue>jgornick</customfieldvalue>
            <customfieldvalue>jp777</customfieldvalue>
            <customfieldvalue>mattalbright</customfieldvalue>
            <customfieldvalue>prateek.ashtikar512@gmail.com</customfieldvalue>
            <customfieldvalue>betawarz</customfieldvalue>
            <customfieldvalue>bawongfai</customfieldvalue>
            <customfieldvalue>sudhanshu94</customfieldvalue>
            <customfieldvalue>iamacoderguy@gmail.com</customfieldvalue>
            <customfieldvalue>tony-kerz</customfieldvalue>
            <customfieldvalue>tzury</customfieldvalue>
            <customfieldvalue>wwwes</customfieldvalue>
            <customfieldvalue>mazgo.wissem@gmail.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpmz3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr2gs7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4561</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrlu6f:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>