title: Spring Data MongoDB - Long values are coming null in response using Repository query
body: <p>I am developing <code>Spring Boot MongoDB</code> example using <code>V2.4.5</code>. In this example when I am doing repository query, Long fields values are not getting mapped. Sample document value from MongoDB.</p>
  <pre><code>{
      &quot;_id&quot; : ObjectId(&quot;60a536412306ab5bdd7a6b06&quot;),
      &quot;user&quot; : {
          &quot;id&quot; : 1,
          &quot;firstname&quot; : &quot;vins&quot;,
          &quot;lastname&quot; : &quot;guru&quot;,
          &quot;email&quot; : &quot;admin@vinsguru.com&quot;
      },
      &quot;product&quot; : {
          &quot;id&quot; : 1,
          &quot;description&quot; : &quot;ipad&quot;
      },
      &quot;price&quot; : 300
  }
  </code></pre>
  <p>OrderController.java</p>
  <pre><code>@RestController
  @RequestMapping(&quot;/order-service&quot;)
  public class OrderController {
      @Autowired
      private PurchaseOrderService purchaseOrderService;
  
      @GetMapping(&quot;/all&quot;)
      public List&lt;PurchaseOrder&gt; getAllOrders() {
          return this.purchaseOrderService.getPurchaseOrders();
      }
  
      @PostMapping(&quot;/create&quot;)
      public void createOrder(@RequestBody PurchaseOrder purchaseOrder) {
          this.purchaseOrderService.createPurchaseOrder(purchaseOrder);
      }
  }
  </code></pre>
  <p>PurchaseOrderServiceImpl.java</p>
  <pre><code>@Service
  public class PurchaseOrderServiceImpl implements PurchaseOrderService {
  
      @Autowired
      private PurchaseOrderRepository purchaseOrderRepository;
  
      @Override
      public List&lt;PurchaseOrder&gt; getPurchaseOrders() {
          return this.purchaseOrderRepository.findAll();
      }
  
      @Override
      public void createPurchaseOrder(PurchaseOrder purchaseOrder) {
          this.purchaseOrderRepository.save(purchaseOrder);
      }
  
  }
  </code></pre>
  <p>PurchaseOrder.java</p>
  <pre><code>@AllArgsConstructor
  @NoArgsConstructor
  @Data
  @Builder
  @Document(collection = &quot;purchase_order&quot;)
  public class PurchaseOrder {
      @Id
      private Long id;
      private User user;
      private Product product;
      private double price;
  }
  </code></pre>
  <p>User.java</p>
  <pre><code>@AllArgsConstructor
  @NoArgsConstructor
  @Data
  @Builder
  public class User {
      private Long id;
      private String firstname;
      private String lastname;
      private String email;
  }
  </code></pre>
  <p>Product.java</p>
  <pre><code>@AllArgsConstructor
  @NoArgsConstructor
  @Data
  @Builder
  public class Product {
      private Long id;
      private String description;
  }
  </code></pre>
  <p>Output I am getting is</p>
  <pre><code>{
      &quot;_id&quot; : ObjectId(&quot;60a536412306ab5bdd7a6b06&quot;),
      &quot;user&quot; : {
          &quot;id&quot; : null,
          &quot;firstname&quot; : &quot;vins&quot;,
          &quot;lastname&quot; : &quot;guru&quot;,
          &quot;email&quot; : &quot;admin@vinsguru.com&quot;
      },
      &quot;product&quot; : {
          &quot;id&quot; : null,
          &quot;description&quot; : &quot;ipad&quot;
      },
      &quot;price&quot; : 300
  }
  </code></pre>
  <p>PurchaseRepository.java</p>
  <pre><code>public interface PurchaseOrderRepository extends MongoRepository&lt;PurchaseOrder, String&gt; {
      @Query(&quot;{ 'user.id': ?0 }&quot;)
      List&lt;PurchaseOrder&gt; findByUserId(Long userId);
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/P7CW7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P7CW7.png" alt="enter image description here" /></a></p>